diff --git a/sdk/sql/azure-mgmt-sql/_meta.json b/sdk/sql/azure-mgmt-sql/_meta.json index 7d5073a6c099e..a6385f642b347 100644 --- a/sdk/sql/azure-mgmt-sql/_meta.json +++ b/sdk/sql/azure-mgmt-sql/_meta.json @@ -1,11 +1,11 @@ { - "autorest": "3.7.2", + "autorest": "3.8.4", "use": [ - "@autorest/python@5.16.0", - "@autorest/modelerfour@4.19.3" + "@autorest/python@6.0.1", + "@autorest/modelerfour@4.23.5" ], - "commit": "b9b91929c304f8fb44002267b6c98d9fb9dde014", + "commit": "7c0fd92095676dfe4f9a72cb7e0c7495f72b4463", "repository_url": "https://github.com/Azure/azure-rest-api-specs", - "autorest_command": "autorest specification/sql/resource-manager/readme.md --python --python-sdks-folder=/home/vsts/work/1/azure-sdk-for-python/sdk --python3-only --use=@autorest/python@5.16.0 --use=@autorest/modelerfour@4.19.3 --version=3.7.2", + "autorest_command": "autorest specification/sql/resource-manager/readme.md --models-mode=msrest --python --python-sdks-folder=/mnt/vss/_work/1/s/azure-sdk-for-python/sdk --use=@autorest/python@6.0.1 --use=@autorest/modelerfour@4.23.5 --version=3.8.4 --version-tolerant=False", "readme": "specification/sql/resource-manager/readme.md" } \ No newline at end of file diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/__init__.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/__init__.py index 663e71b597fd1..3e48c88c1ab08 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/__init__.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/__init__.py @@ -17,7 +17,8 @@ except ImportError: _patch_all = [] from ._patch import patch_sdk as _patch_sdk -__all__ = ['SqlManagementClient'] + +__all__ = ["SqlManagementClient"] __all__.extend([p for p in _patch_all if p not in __all__]) _patch_sdk() diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_configuration.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_configuration.py index 2ad93caaee8fb..e87ddb448728e 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_configuration.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_configuration.py @@ -25,18 +25,13 @@ class SqlManagementClientConfiguration(Configuration): # pylint: disable=too-ma Note that all parameters used to create this instance are saved as instance attributes. - :param credential: Credential needed for the client to connect to Azure. + :param credential: Credential needed for the client to connect to Azure. Required. :type credential: ~azure.core.credentials.TokenCredential - :param subscription_id: The subscription ID that identifies an Azure subscription. + :param subscription_id: The subscription ID that identifies an Azure subscription. Required. :type subscription_id: str """ - def __init__( - self, - credential: "TokenCredential", - subscription_id: str, - **kwargs: Any - ) -> None: + def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs: Any) -> None: super(SqlManagementClientConfiguration, self).__init__(**kwargs) if credential is None: raise ValueError("Parameter 'credential' must not be None.") @@ -45,23 +40,24 @@ def __init__( self.credential = credential self.subscription_id = subscription_id - self.credential_scopes = kwargs.pop('credential_scopes', ['https://management.azure.com/.default']) - kwargs.setdefault('sdk_moniker', 'mgmt-sql/{}'.format(VERSION)) + self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) + kwargs.setdefault("sdk_moniker", "mgmt-sql/{}".format(VERSION)) self._configure(**kwargs) def _configure( - self, - **kwargs # type: Any + self, **kwargs # type: Any ): # type: (...) -> 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.authentication_policy = kwargs.get('authentication_policy') + 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.authentication_policy = kwargs.get("authentication_policy") if self.credential and not self.authentication_policy: - self.authentication_policy = ARMChallengeAuthenticationPolicy(self.credential, *self.credential_scopes, **kwargs) + self.authentication_policy = ARMChallengeAuthenticationPolicy( + self.credential, *self.credential_scopes, **kwargs + ) diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_patch.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_patch.py index 74e48ecd07cf3..f99e77fef9861 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_patch.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_patch.py @@ -28,4 +28,4 @@ # This file is used for handwritten extensions to the generated code. Example: # https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md def patch_sdk(): - pass \ No newline at end of file + pass diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_serialization.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_serialization.py new file mode 100644 index 0000000000000..648f84cc4e653 --- /dev/null +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_serialization.py @@ -0,0 +1,1970 @@ +# -------------------------------------------------------------------------- +# +# 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. +# +# -------------------------------------------------------------------------- + +# pylint: skip-file + +from base64 import b64decode, b64encode +import calendar +import datetime +import decimal +import email +from enum import Enum +import json +import logging +import re +import sys +import codecs + +try: + from urllib import quote # type: ignore +except ImportError: + from urllib.parse import quote # type: ignore +import xml.etree.ElementTree as ET + +import isodate + +from typing import Dict, Any, cast, TYPE_CHECKING + +from azure.core.exceptions import DeserializationError, SerializationError, raise_with_traceback + +_BOM = codecs.BOM_UTF8.decode(encoding="utf-8") + +if TYPE_CHECKING: + from typing import Optional, Union, AnyStr, IO, Mapping + + +class RawDeserializer: + + # Accept "text" because we're open minded people... + JSON_REGEXP = re.compile(r"^(application|text)/([a-z+.]+\+)?json$") + + # Name used in context + CONTEXT_NAME = "deserialized_data" + + @classmethod + def deserialize_from_text(cls, data, content_type=None): + # type: (Optional[Union[AnyStr, IO]], Optional[str]) -> Any + """Decode data according to content-type. + + Accept a stream of data as well, but will be load at once in memory for now. + + If no content-type, will return the string version (not bytes, not stream) + + :param data: Input, could be bytes or stream (will be decoded with UTF8) or text + :type data: str or bytes or IO + :param str content_type: The content type. + """ + if hasattr(data, "read"): + # Assume a stream + data = cast(IO, data).read() + + if isinstance(data, bytes): + data_as_str = data.decode(encoding="utf-8-sig") + else: + # Explain to mypy the correct type. + data_as_str = cast(str, data) + + # Remove Byte Order Mark if present in string + data_as_str = data_as_str.lstrip(_BOM) + + if content_type is None: + return data + + if cls.JSON_REGEXP.match(content_type): + try: + return json.loads(data_as_str) + except ValueError as err: + raise DeserializationError("JSON is invalid: {}".format(err), err) + elif "xml" in (content_type or []): + try: + + try: + if isinstance(data, unicode): # type: ignore + # If I'm Python 2.7 and unicode XML will scream if I try a "fromstring" on unicode string + data_as_str = data_as_str.encode(encoding="utf-8") # type: ignore + except NameError: + pass + + return ET.fromstring(data_as_str) # nosec + except ET.ParseError: + # 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 + # let's flow the initial exception + def _json_attemp(data): + try: + return True, json.loads(data) + except ValueError: + return False, None # Don't care about this one + + success, json_result = _json_attemp(data) + if success: + return json_result + # If i'm here, it's not JSON, it's not XML, let's scream + # and raise the last context in this block (the XML exception) + # 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("Cannot deserialize content-type: {}".format(content_type)) + + @classmethod + def deserialize_from_http_generics(cls, body_bytes, headers): + # type: (Optional[Union[AnyStr, IO]], Mapping) -> Any + """Deserialize from HTTP response. + + Use bytes and headers to NOT use any requests/aiohttp or whatever + specific implementation. + Headers will tested for "content-type" + """ + # Try to use content-type from headers if available + content_type = None + if "content-type" in headers: + content_type = headers["content-type"].split(";")[0].strip().lower() + # Ouch, this server did not declare what it sent... + # Let's guess it's JSON... + # Also, since Autorest was considering that an empty body was a valid JSON, + # need that test as well.... + else: + content_type = "application/json" + + if body_bytes: + return cls.deserialize_from_text(body_bytes, content_type) + 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: + _long_type = long # type: ignore +except NameError: + _long_type = int + + +class UTC(datetime.tzinfo): + """Time Zone info for handling UTC""" + + def utcoffset(self, dt): + """UTF offset for UTC is 0.""" + return datetime.timedelta(0) + + def tzname(self, dt): + """Timestamp representation.""" + return "Z" + + def dst(self, dt): + """No daylight saving for UTC.""" + return datetime.timedelta(hours=1) + + +try: + from datetime import timezone as _FixedOffset +except ImportError: # Python 2.7 + + class _FixedOffset(datetime.tzinfo): # type: ignore + """Fixed offset in minutes east from UTC. + Copy/pasted from Python doc + :param datetime.timedelta offset: offset in timedelta format + """ + + def __init__(self, offset): + self.__offset = offset + + def utcoffset(self, dt): + return self.__offset + + def tzname(self, dt): + return str(self.__offset.total_seconds() / 3600) + + def __repr__(self): + return "".format(self.tzname(None)) + + def dst(self, dt): + return datetime.timedelta(0) + + def __getinitargs__(self): + return (self.__offset,) + + +try: + from datetime import timezone + + TZ_UTC = timezone.utc # type: ignore +except ImportError: + TZ_UTC = UTC() # type: ignore + +_FLATTEN = re.compile(r"(? y, + "minimum": lambda x, y: x < y, + "maximum": lambda x, y: x > y, + "minimum_ex": lambda x, y: x <= y, + "maximum_ex": lambda x, y: x >= y, + "min_items": lambda x, y: len(x) < y, + "max_items": lambda x, y: len(x) > y, + "pattern": lambda x, y: not re.match(y, x, re.UNICODE), + "unique": lambda x, y: len(x) != len(set(x)), + "multiple": lambda x, y: x % y != 0, + } + + def __init__(self, classes=None): + self.serialize_type = { + "iso-8601": Serializer.serialize_iso, + "rfc-1123": Serializer.serialize_rfc, + "unix-time": Serializer.serialize_unix, + "duration": Serializer.serialize_duration, + "date": Serializer.serialize_date, + "time": Serializer.serialize_time, + "decimal": Serializer.serialize_decimal, + "long": Serializer.serialize_long, + "bytearray": Serializer.serialize_bytearray, + "base64": Serializer.serialize_base64, + "object": self.serialize_object, + "[]": self.serialize_iter, + "{}": self.serialize_dict, + } + self.dependencies = dict(classes) if classes else {} + self.key_transformer = full_restapi_key_transformer + self.client_side_validation = True + + def _serialize(self, target_obj, data_type=None, **kwargs): + """Serialize data into a string according to type. + + :param target_obj: The data to be serialized. + :param str data_type: The type to be serialized from. + :rtype: str, dict + :raises: SerializationError if serialization fails. + """ + key_transformer = kwargs.get("key_transformer", self.key_transformer) + keep_readonly = kwargs.get("keep_readonly", False) + if target_obj is None: + return None + + attr_name = None + class_name = target_obj.__class__.__name__ + + if data_type: + return self.serialize_data(target_obj, data_type, **kwargs) + + if not hasattr(target_obj, "_attribute_map"): + data_type = type(target_obj).__name__ + if data_type in self.basic_types.values(): + return self.serialize_data(target_obj, data_type, **kwargs) + + # Force "is_xml" kwargs if we detect a XML model + try: + is_xml_model_serialization = kwargs["is_xml"] + except KeyError: + is_xml_model_serialization = kwargs.setdefault("is_xml", target_obj.is_xml_model()) + + serialized = {} + if is_xml_model_serialization: + serialized = target_obj._create_xml_node() + try: + attributes = target_obj._attribute_map + for attr, attr_desc in attributes.items(): + attr_name = attr + if not keep_readonly and target_obj._validation.get(attr_name, {}).get("readonly", False): + continue + + if attr_name == "additional_properties" and attr_desc["key"] == "": + if target_obj.additional_properties is not None: + serialized.update(target_obj.additional_properties) + continue + try: + + orig_attr = getattr(target_obj, attr) + if is_xml_model_serialization: + pass # Don't provide "transformer" for XML for now. Keep "orig_attr" + else: # JSON + keys, orig_attr = key_transformer(attr, attr_desc.copy(), orig_attr) + keys = keys if isinstance(keys, list) else [keys] + + kwargs["serialization_ctxt"] = attr_desc + new_attr = self.serialize_data(orig_attr, attr_desc["type"], **kwargs) + + if is_xml_model_serialization: + xml_desc = attr_desc.get("xml", {}) + xml_name = xml_desc.get("name", attr_desc["key"]) + xml_prefix = xml_desc.get("prefix", None) + xml_ns = xml_desc.get("ns", None) + 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) + continue + if xml_desc.get("text", False): + serialized.text = new_attr + continue + if isinstance(new_attr, list): + serialized.extend(new_attr) + 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", {}): + splitted_tag = new_attr.tag.split("}") + if len(splitted_tag) == 2: # Namespace + new_attr.tag = "}".join([splitted_tag[0], xml_name]) + else: + new_attr.tag = xml_name + serialized.append(new_attr) + 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) + else: # JSON + for k in reversed(keys): + unflattened = {k: new_attr} + new_attr = unflattened + + _new_attr = new_attr + _serialized = serialized + for k in keys: + if k not in _serialized: + _serialized.update(_new_attr) + _new_attr = _new_attr[k] + _serialized = _serialized[k] + except ValueError: + continue + + 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) + else: + return serialized + + def body(self, data, data_type, **kwargs): + """Serialize data intended for a request body. + + :param data: The data to be serialized. + :param str data_type: The type to be serialized from. + :rtype: dict + :raises: SerializationError if serialization fails. + :raises: ValueError if data is None + """ + + # Just in case this is a dict + internal_data_type = data_type.strip("[]{}") + internal_data_type = self.dependencies.get(internal_data_type, None) + try: + is_xml_model_serialization = kwargs["is_xml"] + except KeyError: + if internal_data_type and issubclass(internal_data_type, Model): + is_xml_model_serialization = kwargs.setdefault("is_xml", internal_data_type.is_xml_model()) + else: + is_xml_model_serialization = False + if internal_data_type and not isinstance(internal_data_type, Enum): + try: + deserializer = Deserializer(self.dependencies) + # Since it's on serialization, it's almost sure that format is not JSON REST + # We're not able to deal with additional properties for now. + deserializer.additional_properties_detection = False + if is_xml_model_serialization: + deserializer.key_extractors = [ + attribute_key_case_insensitive_extractor, + ] + else: + deserializer.key_extractors = [ + rest_key_case_insensitive_extractor, + attribute_key_case_insensitive_extractor, + last_rest_key_case_insensitive_extractor, + ] + data = deserializer._deserialize(data_type, data) + except DeserializationError as err: + raise_with_traceback(SerializationError, "Unable to build a model: " + str(err), err) + + return self._serialize(data, data_type, **kwargs) + + def url(self, name, data, data_type, **kwargs): + """Serialize data intended for a URL path. + + :param data: The data to be serialized. + :param str data_type: The type to be serialized from. + :rtype: str + :raises: TypeError if serialization fails. + :raises: ValueError if data is None + """ + try: + output = self.serialize_data(data, data_type, **kwargs) + if data_type == "bool": + output = json.dumps(output) + + if kwargs.get("skip_quote") is True: + output = str(output) + else: + output = quote(str(output), safe="") + except SerializationError: + raise TypeError("{} must be type {}.".format(name, data_type)) + else: + return output + + def query(self, name, data, data_type, **kwargs): + """Serialize data intended for a URL query. + + :param data: The data to be serialized. + :param str data_type: The type to be serialized from. + :rtype: str + :raises: TypeError if serialization fails. + :raises: ValueError if data is None + """ + try: + # 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)) + + # Not a list, regular serialization + output = self.serialize_data(data, data_type, **kwargs) + if data_type == "bool": + output = json.dumps(output) + if kwargs.get("skip_quote") is True: + output = str(output) + else: + output = quote(str(output), safe="") + except SerializationError: + raise TypeError("{} must be type {}.".format(name, data_type)) + else: + return str(output) + + def header(self, name, data, data_type, **kwargs): + """Serialize data intended for a request header. + + :param data: The data to be serialized. + :param str data_type: The type to be serialized from. + :rtype: str + :raises: TypeError if serialization fails. + :raises: ValueError if data is None + """ + try: + if data_type in ["[str]"]: + data = ["" if d is None else d for d in data] + + output = self.serialize_data(data, data_type, **kwargs) + if data_type == "bool": + output = json.dumps(output) + except SerializationError: + raise TypeError("{} must be type {}.".format(name, data_type)) + else: + return str(output) + + def serialize_data(self, data, data_type, **kwargs): + """Serialize generic data according to supplied data type. + + :param data: The data to be serialized. + :param str data_type: The type to be serialized from. + :param bool required: Whether it's essential that the data not be + empty or None + :raises: AttributeError if required data is None. + :raises: ValueError if data is None + :raises: SerializationError if serialization fails. + """ + if data is None: + raise ValueError("No value for given attribute") + + try: + if data_type in self.basic_types.values(): + return self.serialize_basic(data, data_type, **kwargs) + + elif data_type in self.serialize_type: + return self.serialize_type[data_type](data, **kwargs) + + # If dependencies is empty, try with current data class + # It has to be a subclass of Enum anyway + enum_type = self.dependencies.get(data_type, data.__class__) + if issubclass(enum_type, Enum): + return Serializer.serialize_enum(data, enum_obj=enum_type) + + iter_type = data_type[0] + data_type[-1] + if iter_type in self.serialize_type: + return self.serialize_type[iter_type](data, data_type[1:-1], **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) + else: + return self._serialize(data, **kwargs) + + @classmethod + def _get_custom_serializers(cls, data_type, **kwargs): + custom_serializer = kwargs.get("basic_types_serializers", {}).get(data_type) + if custom_serializer: + return custom_serializer + if kwargs.get("is_xml", False): + return cls._xml_basic_types_serializers.get(data_type) + + @classmethod + def serialize_basic(cls, data, data_type, **kwargs): + """Serialize basic builting data type. + Serializes objects to str, int, float or bool. + + Possible kwargs: + - basic_types_serializers dict[str, callable] : If set, use the callable as serializer + - is_xml bool : If set, use xml_basic_types_serializers + + :param data: Object to be serialized. + :param str data_type: Type of object in the iterable. + """ + custom_serializer = cls._get_custom_serializers(data_type, **kwargs) + if custom_serializer: + return custom_serializer(data) + if data_type == "str": + return cls.serialize_unicode(data) + return eval(data_type)(data) # nosec + + @classmethod + def serialize_unicode(cls, data): + """Special handling for serializing unicode strings in Py2. + Encode to UTF-8 if unicode, otherwise handle as a str. + + :param data: Object to be serialized. + :rtype: str + """ + try: # If I received an enum, return its value + return data.value + except AttributeError: + pass + + try: + if isinstance(data, unicode): + # Don't change it, JSON and XML ElementTree are totally able + # to serialize correctly u'' strings + return data + except NameError: + return str(data) + else: + return str(data) + + def serialize_iter(self, data, iter_type, div=None, **kwargs): + """Serialize iterable. + + Supported kwargs: + - serialization_ctxt dict : The current entry of _attribute_map, or same format. + serialization_ctxt['type'] should be same as data_type. + - is_xml bool : If set, serialize as XML + + :param list attr: Object to be serialized. + :param str iter_type: Type of object in the iterable. + :param bool required: Whether the objects in the iterable must + 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'. + :rtype: list, str + """ + if isinstance(data, str): + raise SerializationError("Refuse str type as a valid iter type.") + + serialization_ctxt = kwargs.get("serialization_ctxt", {}) + is_xml = kwargs.get("is_xml", False) + + serialized = [] + for d in data: + try: + serialized.append(self.serialize_data(d, iter_type, **kwargs)) + except ValueError: + serialized.append(None) + + if div: + serialized = ["" if s is None else str(s) for s in serialized] + serialized = div.join(serialized) + + if "xml" in serialization_ctxt or is_xml: + # XML serialization is more complicated + xml_desc = serialization_ctxt.get("xml", {}) + xml_name = xml_desc.get("name") + if not xml_name: + xml_name = serialization_ctxt["key"] + + # Create a wrap node if necessary (use the fact that Element and list have "append") + is_wrapped = xml_desc.get("wrapped", False) + node_name = xml_desc.get("itemsName", xml_name) + if is_wrapped: + final_result = _create_xml_node(xml_name, xml_desc.get("prefix", None), xml_desc.get("ns", None)) + else: + final_result = [] + # All list elements to "local_node" + for el in serialized: + if isinstance(el, ET.Element): + el_node = el + else: + el_node = _create_xml_node(node_name, xml_desc.get("prefix", None), xml_desc.get("ns", None)) + if el is not None: # Otherwise it writes "None" :-p + el_node.text = str(el) + final_result.append(el_node) + return final_result + return serialized + + def serialize_dict(self, attr, dict_type, **kwargs): + """Serialize a dictionary of objects. + + :param dict attr: Object to be serialized. + :param str dict_type: Type of object in the dictionary. + :param bool required: Whether the objects in the dictionary must + not be None or empty. + :rtype: dict + """ + serialization_ctxt = kwargs.get("serialization_ctxt", {}) + serialized = {} + for key, value in attr.items(): + try: + serialized[self.serialize_unicode(key)] = self.serialize_data(value, dict_type, **kwargs) + except ValueError: + serialized[self.serialize_unicode(key)] = None + + if "xml" in serialization_ctxt: + # XML serialization is more complicated + xml_desc = serialization_ctxt["xml"] + xml_name = xml_desc["name"] + + final_result = _create_xml_node(xml_name, xml_desc.get("prefix", None), xml_desc.get("ns", None)) + for key, value in serialized.items(): + ET.SubElement(final_result, key).text = value + return final_result + + return serialized + + def serialize_object(self, attr, **kwargs): + """Serialize a generic object. + This will be handled as a dictionary. If object passed in is not + a basic type (str, int, float, dict, list) it will simply be + cast to str. + + :param dict attr: Object to be serialized. + :rtype: dict or str + """ + if attr is None: + return None + if isinstance(attr, ET.Element): + return attr + obj_type = type(attr) + if obj_type in self.basic_types: + 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: + return self.serialize_unicode(attr) + if obj_type is datetime.datetime: + return self.serialize_iso(attr) + if obj_type is datetime.date: + return self.serialize_date(attr) + if obj_type is datetime.time: + return self.serialize_time(attr) + if obj_type is datetime.timedelta: + return self.serialize_duration(attr) + if obj_type is decimal.Decimal: + return self.serialize_decimal(attr) + + # If it's a model or I know this dependency, serialize as a Model + elif obj_type in self.dependencies.values() or isinstance(attr, Model): + return self._serialize(attr) + + if obj_type == dict: + serialized = {} + for key, value in attr.items(): + try: + serialized[self.serialize_unicode(key)] = self.serialize_object(value, **kwargs) + except ValueError: + serialized[self.serialize_unicode(key)] = None + return serialized + + if obj_type == list: + serialized = [] + for obj in attr: + try: + serialized.append(self.serialize_object(obj, **kwargs)) + except ValueError: + pass + return serialized + return str(attr) + + @staticmethod + def serialize_enum(attr, enum_obj=None): + try: + result = attr.value + except AttributeError: + result = attr + try: + enum_obj(result) + return result + except ValueError: + for enum_value in enum_obj: + if enum_value.value.lower() == str(attr).lower(): + return enum_value.value + error = "{!r} is not valid value for enum {!r}" + raise SerializationError(error.format(attr, enum_obj)) + + @staticmethod + def serialize_bytearray(attr, **kwargs): + """Serialize bytearray into base-64 string. + + :param attr: Object to be serialized. + :rtype: str + """ + return b64encode(attr).decode() + + @staticmethod + def serialize_base64(attr, **kwargs): + """Serialize str into base-64 string. + + :param attr: Object to be serialized. + :rtype: str + """ + encoded = b64encode(attr).decode("ascii") + return encoded.strip("=").replace("+", "-").replace("/", "_") + + @staticmethod + def serialize_decimal(attr, **kwargs): + """Serialize Decimal object to float. + + :param attr: Object to be serialized. + :rtype: float + """ + return float(attr) + + @staticmethod + def serialize_long(attr, **kwargs): + """Serialize long (Py2) or int (Py3). + + :param attr: Object to be serialized. + :rtype: int/long + """ + return _long_type(attr) + + @staticmethod + def serialize_date(attr, **kwargs): + """Serialize Date object into ISO-8601 formatted string. + + :param Date attr: Object to be serialized. + :rtype: str + """ + if isinstance(attr, str): + attr = isodate.parse_date(attr) + t = "{:04}-{:02}-{:02}".format(attr.year, attr.month, attr.day) + return t + + @staticmethod + def serialize_time(attr, **kwargs): + """Serialize Time object into ISO-8601 formatted string. + + :param datetime.time attr: Object to be serialized. + :rtype: str + """ + if isinstance(attr, str): + attr = isodate.parse_time(attr) + t = "{:02}:{:02}:{:02}".format(attr.hour, attr.minute, attr.second) + if attr.microsecond: + t += ".{:02}".format(attr.microsecond) + return t + + @staticmethod + def serialize_duration(attr, **kwargs): + """Serialize TimeDelta object into ISO-8601 formatted string. + + :param TimeDelta attr: Object to be serialized. + :rtype: str + """ + if isinstance(attr, str): + attr = isodate.parse_duration(attr) + return isodate.duration_isoformat(attr) + + @staticmethod + def serialize_rfc(attr, **kwargs): + """Serialize Datetime object into RFC-1123 formatted string. + + :param Datetime attr: Object to be serialized. + :rtype: str + :raises: TypeError if format invalid. + """ + try: + if not attr.tzinfo: + _LOGGER.warning("Datetime with no tzinfo will be considered UTC.") + utc = attr.utctimetuple() + except AttributeError: + raise TypeError("RFC1123 object must be valid Datetime object.") + + return "{}, {:02} {} {:04} {:02}:{:02}:{:02} GMT".format( + Serializer.days[utc.tm_wday], + utc.tm_mday, + Serializer.months[utc.tm_mon], + utc.tm_year, + utc.tm_hour, + utc.tm_min, + utc.tm_sec, + ) + + @staticmethod + def serialize_iso(attr, **kwargs): + """Serialize Datetime object into ISO-8601 formatted string. + + :param Datetime attr: Object to be serialized. + :rtype: str + :raises: SerializationError if format invalid. + """ + if isinstance(attr, str): + attr = isodate.parse_datetime(attr) + try: + if not attr.tzinfo: + _LOGGER.warning("Datetime with no tzinfo will be considered UTC.") + utc = attr.utctimetuple() + if utc.tm_year > 9999 or utc.tm_year < 1: + raise OverflowError("Hit max or min date") + + microseconds = str(attr.microsecond).rjust(6, "0").rstrip("0").ljust(3, "0") + if microseconds: + microseconds = "." + microseconds + date = "{:04}-{:02}-{:02}T{:02}:{:02}:{:02}".format( + utc.tm_year, utc.tm_mon, utc.tm_mday, utc.tm_hour, utc.tm_min, utc.tm_sec + ) + return date + microseconds + "Z" + except (ValueError, OverflowError) as err: + msg = "Unable to serialize datetime object." + raise_with_traceback(SerializationError, msg, err) + except AttributeError as err: + msg = "ISO-8601 object must be valid Datetime object." + raise_with_traceback(TypeError, msg, err) + + @staticmethod + def serialize_unix(attr, **kwargs): + """Serialize Datetime object into IntTime format. + This is represented as seconds. + + :param Datetime attr: Object to be serialized. + :rtype: int + :raises: SerializationError if format invalid + """ + if isinstance(attr, int): + return attr + try: + if not attr.tzinfo: + _LOGGER.warning("Datetime with no tzinfo will be considered UTC.") + return int(calendar.timegm(attr.utctimetuple())) + except AttributeError: + raise TypeError("Unix time object must be valid Datetime object.") + + +def rest_key_extractor(attr, attr_desc, data): + key = attr_desc["key"] + working_data = data + + while "." in key: + dict_keys = _FLATTEN.split(key) + if len(dict_keys) == 1: + key = _decode_attribute_map_key(dict_keys[0]) + break + working_key = _decode_attribute_map_key(dict_keys[0]) + working_data = working_data.get(working_key, 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:]) + + return working_data.get(key) + + +def rest_key_case_insensitive_extractor(attr, attr_desc, data): + key = attr_desc["key"] + working_data = data + + while "." in key: + dict_keys = _FLATTEN.split(key) + if len(dict_keys) == 1: + key = _decode_attribute_map_key(dict_keys[0]) + break + working_key = _decode_attribute_map_key(dict_keys[0]) + working_data = attribute_key_case_insensitive_extractor(working_key, None, working_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:]) + + if working_data: + return attribute_key_case_insensitive_extractor(key, None, working_data) + + +def last_rest_key_extractor(attr, attr_desc, data): + """Extract the attribute in "data" based on the last part of the JSON path key.""" + key = attr_desc["key"] + dict_keys = _FLATTEN.split(key) + return attribute_key_extractor(dict_keys[-1], None, data) + + +def last_rest_key_case_insensitive_extractor(attr, attr_desc, data): + """Extract the attribute in "data" based on the last part of the JSON path key. + + This is the case insensitive version of "last_rest_key_extractor" + """ + key = attr_desc["key"] + dict_keys = _FLATTEN.split(key) + return attribute_key_case_insensitive_extractor(dict_keys[-1], None, data) + + +def attribute_key_extractor(attr, _, data): + return data.get(attr) + + +def attribute_key_case_insensitive_extractor(attr, _, data): + found_key = None + lower_attr = attr.lower() + for key in data: + if lower_attr == key.lower(): + found_key = key + break + + return data.get(found_key) + + +def _extract_name_from_internal_type(internal_type): + """Given an internal type XML description, extract correct XML name with namespace. + + :param dict internal_type: An model type + :rtype: tuple + :returns: A tuple XML name + namespace dict + """ + internal_type_xml_map = getattr(internal_type, "_xml_map", {}) + 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) + return xml_name + + +def xml_key_extractor(attr, attr_desc, data): + if isinstance(data, dict): + return None + + # Test if this model is XML ready first + if not isinstance(data, ET.Element): + return None + + xml_desc = attr_desc.get("xml", {}) + xml_name = xml_desc.get("name", attr_desc["key"]) + + # Look for a children + is_iter_type = attr_desc["type"].startswith("[") + is_wrapped = xml_desc.get("wrapped", False) + internal_type = attr_desc.get("internalType", None) + internal_type_xml_map = getattr(internal_type, "_xml_map", {}) + + # 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) + + # If it's an attribute, that's simple + if xml_desc.get("attr", False): + return data.get(xml_name) + + # If it's x-ms-text, that's simple too + if xml_desc.get("text", False): + return data.text + + # Scenario where I take the local name: + # - Wrapped node + # - Internal type is an enum (considered basic types) + # - Internal type has no XML/Name node + if is_wrapped or (internal_type and (issubclass(internal_type, Enum) or "name" not in internal_type_xml_map)): + children = data.findall(xml_name) + # If internal type has a local name and it's not a list, I use that name + elif not is_iter_type and internal_type and "name" in internal_type_xml_map: + xml_name = _extract_name_from_internal_type(internal_type) + children = data.findall(xml_name) + # That's an array + else: + if internal_type: # Complex type, ignore itemsName and use the complex type name + items_name = _extract_name_from_internal_type(internal_type) + else: + items_name = xml_desc.get("itemsName", xml_name) + children = data.findall(items_name) + + if len(children) == 0: + if is_iter_type: + if is_wrapped: + return None # is_wrapped no node, we want None + else: + return [] # not wrapped, assume empty list + return None # Assume it's not there, maybe an optional node. + + # If is_iter_type and not wrapped, return all found children + if is_iter_type: + if not is_wrapped: + return children + else: # Iter and wrapped, should have found one node only (the wrap one) + if len(children) != 1: + raise DeserializationError( + "Tried to deserialize an array not wrapped, and found several nodes '{}'. Maybe you should declare this array as wrapped?".format( + xml_name + ) + ) + return list(children[0]) # Might be empty list and that's ok. + + # Here it's not a itertype, we should have found one element only or empty + if len(children) > 1: + raise DeserializationError("Find several XML '{}' where it was not expected".format(xml_name)) + return children[0] + + +class Deserializer(object): + """Response object model deserializer. + + :param dict classes: Class type dictionary for deserializing complex types. + :ivar list key_extractors: Ordered list of extractors to be used by this deserializer. + """ + + basic_types = {str: "str", int: "int", bool: "bool", float: "float"} + + 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): + self.deserialize_type = { + "iso-8601": Deserializer.deserialize_iso, + "rfc-1123": Deserializer.deserialize_rfc, + "unix-time": Deserializer.deserialize_unix, + "duration": Deserializer.deserialize_duration, + "date": Deserializer.deserialize_date, + "time": Deserializer.deserialize_time, + "decimal": Deserializer.deserialize_decimal, + "long": Deserializer.deserialize_long, + "bytearray": Deserializer.deserialize_bytearray, + "base64": Deserializer.deserialize_base64, + "object": self.deserialize_object, + "[]": self.deserialize_iter, + "{}": self.deserialize_dict, + } + self.deserialize_expected_types = { + "duration": (isodate.Duration, datetime.timedelta), + "iso-8601": (datetime.datetime), + } + self.dependencies = 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 + # complicated, with no real scenario for now. + # So adding a flag to disable additional properties detection. This flag should be + # used if your expect the deserialization to NOT come from a JSON REST syntax. + # Otherwise, result are unexpected + self.additional_properties_detection = True + + def __call__(self, target_obj, response_data, content_type=None): + """Call the deserializer to process a REST response. + + :param str target_obj: Target data type to deserialize to. + :param requests.Response response_data: REST response object. + :param str content_type: Swagger "produces" if available. + :raises: DeserializationError if deserialization fails. + :return: Deserialized object. + """ + data = self._unpack_content(response_data, content_type) + return self._deserialize(target_obj, data) + + def _deserialize(self, target_obj, data): + """Call the deserializer on a model. + + Data needs to be already deserialized as JSON or XML ElementTree + + :param str target_obj: Target data type to deserialize to. + :param object data: Object to deserialize. + :raises: DeserializationError if deserialization fails. + :return: Deserialized object. + """ + # This is already a model, go recursive just in case + if hasattr(data, "_attribute_map"): + constants = [name for name, config in getattr(data, "_validation", {}).items() if config.get("constant")] + try: + for attr, mapconfig in data._attribute_map.items(): + if attr in constants: + continue + value = getattr(data, attr) + if value is None: + continue + local_type = mapconfig["type"] + internal_data_type = local_type.strip("[]{}") + if internal_data_type not in self.dependencies or isinstance(internal_data_type, Enum): + continue + setattr(data, attr, self._deserialize(local_type, value)) + return data + except AttributeError: + return + + response, class_name = self._classify_target(target_obj, data) + + if isinstance(response, basestring): + return self.deserialize_data(data, response) + elif isinstance(response, type) and issubclass(response, Enum): + return self.deserialize_enum(data, response) + + if data is None: + return data + try: + attributes = response._attribute_map + d_attrs = {} + for attr, attr_desc in attributes.items(): + # Check empty string. If it's not empty, someone has a real "additionalProperties"... + if attr == "additional_properties" and attr_desc["key"] == "": + continue + raw_value = None + # Enhance attr_desc with some dynamic data + attr_desc = attr_desc.copy() # Do a copy, do not change the real one + internal_data_type = attr_desc["type"].strip("[]{}") + if internal_data_type in self.dependencies: + attr_desc["internalType"] = self.dependencies[internal_data_type] + + for key_extractor in self.key_extractors: + found_value = key_extractor(attr, attr_desc, data) + if found_value is not None: + if raw_value is not None and raw_value != found_value: + msg = ( + "Ignoring extracted value '%s' from %s for key '%s'" + " (duplicate extraction, follow extractors order)" + ) + _LOGGER.warning(msg, found_value, key_extractor, attr) + continue + raw_value = found_value + + 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) + else: + additional_properties = self._build_additional_properties(attributes, data) + return self._instantiate_model(response, d_attrs, additional_properties) + + def _build_additional_properties(self, attribute_map, data): + if not self.additional_properties_detection: + return None + if "additional_properties" in attribute_map and attribute_map.get("additional_properties", {}).get("key") != "": + # Check empty string. If it's not empty, someone has a real "additionalProperties" + return None + if isinstance(data, ET.Element): + data = {el.tag: el.text for el in data} + + known_keys = { + _decode_attribute_map_key(_FLATTEN.split(desc["key"])[0]) + for desc in attribute_map.values() + if desc["key"] != "" + } + present_keys = set(data.keys()) + missing_keys = present_keys - known_keys + return {key: data[key] for key in missing_keys} + + def _classify_target(self, target, data): + """Check to see whether the deserialization target object can + be classified into a subclass. + 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. + """ + if target is None: + return None, None + + if isinstance(target, basestring): + try: + target = self.dependencies[target] + except KeyError: + return target, target + + try: + target = target._classify(data, self.dependencies) + except AttributeError: + pass # Target is not a Model, no classify + return target, target.__class__.__name__ + + def failsafe_deserialize(self, target_obj, data, content_type=None): + """Ignores any errors encountered in deserialization, + and falls back to not deserializing the object. Recommended + for use in error deserialization, as we want to return the + HttpResponseError to users, and not have them deal with + 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 content_type: Swagger "produces" if available. + """ + try: + return self(target_obj, data, content_type=content_type) + except: + _LOGGER.warning( + "Ran into a deserialization error. Ignoring since this is failsafe deserialization", exc_info=True + ) + return None + + @staticmethod + def _unpack_content(raw_data, content_type=None): + """Extract the correct structure for deserialization. + + If raw_data is a PipelineResponse, try to extract the result of RawDeserializer. + if we can't, raise. Your Pipeline should have a RawDeserializer. + + If not a pipeline response and raw_data is bytes or string, use content-type + to decode it. If no content-type, try JSON. + + If raw_data is something else, bypass all logic and return it directly. + + :param raw_data: Data to be processed. + :param content_type: How to parse if raw_data is a string/bytes. + :raises JSONDecodeError: If JSON is requested and parsing is impossible. + :raises UnicodeDecodeError: If bytes is not UTF8 + """ + # Assume this is enough to detect a Pipeline Response without importing it + context = getattr(raw_data, "context", {}) + if context: + if RawDeserializer.CONTEXT_NAME in context: + return context[RawDeserializer.CONTEXT_NAME] + raise ValueError("This pipeline didn't have the RawDeserializer policy; can't deserialize") + + # Assume this is enough to recognize universal_http.ClientResponse without importing it + if hasattr(raw_data, "body"): + return RawDeserializer.deserialize_from_http_generics(raw_data.text(), raw_data.headers) + + # Assume this enough to recognize requests.Response without importing it. + 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) + return raw_data + + def _instantiate_model(self, response, attrs, additional_properties=None): + """Instantiate a response model passing in deserialized args. + + :param response: The response model class. + :param d_attrs: The deserialized response attributes. + """ + if callable(response): + subtype = getattr(response, "_subtype_map", {}) + try: + readonly = [k for k, v in response._validation.items() if v.get("readonly")] + const = [k for k, v in response._validation.items() if v.get("constant")] + kwargs = {k: v for k, v in attrs.items() if k not in subtype and k not in readonly + const} + response_obj = response(**kwargs) + for attr in readonly: + setattr(response_obj, attr, attrs.get(attr)) + if additional_properties: + response_obj.additional_properties = additional_properties + return response_obj + except TypeError as err: + msg = "Unable to deserialize {} into model {}. ".format(kwargs, response) + raise DeserializationError(msg + str(err)) + else: + try: + for attr, value in attrs.items(): + setattr(response, attr, value) + return response + except Exception as exp: + msg = "Unable to populate response model. " + msg += "Type: {}, Error: {}".format(type(response), exp) + raise DeserializationError(msg) + + def deserialize_data(self, data, data_type): + """Process data for deserialization according to data type. + + :param str data: The response string to be deserialized. + :param str data_type: The type to deserialize to. + :raises: DeserializationError if deserialization fails. + :return: Deserialized object. + """ + if data is None: + return data + + try: + if not data_type: + return data + if data_type in self.basic_types.values(): + return self.deserialize_basic(data, data_type) + if data_type in self.deserialize_type: + if isinstance(data, self.deserialize_expected_types.get(data_type, tuple())): + return data + + is_a_text_parsing_type = lambda x: x not in ["object", "[]", r"{}"] + if isinstance(data, ET.Element) and is_a_text_parsing_type(data_type) and not data.text: + return None + data_val = self.deserialize_type[data_type](data) + return data_val + + iter_type = data_type[0] + data_type[-1] + if iter_type in self.deserialize_type: + return self.deserialize_type[iter_type](data, data_type[1:-1]) + + obj_type = self.dependencies[data_type] + if issubclass(obj_type, Enum): + if isinstance(data, ET.Element): + data = data.text + return self.deserialize_enum(data, obj_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) + else: + return self._deserialize(obj_type, data) + + def deserialize_iter(self, attr, iter_type): + """Deserialize an iterable. + + :param list attr: Iterable to be deserialized. + :param str iter_type: The type of object in the iterable. + :rtype: list + """ + if attr is None: + return None + if isinstance(attr, ET.Element): # If I receive an element here, get the children + attr = list(attr) + if not isinstance(attr, (list, set)): + raise DeserializationError("Cannot deserialize as [{}] an object of type {}".format(iter_type, type(attr))) + return [self.deserialize_data(a, iter_type) for a in attr] + + def deserialize_dict(self, attr, dict_type): + """Deserialize a dictionary. + + :param dict/list attr: Dictionary to be deserialized. Also accepts + a list of key, value pairs. + :param str dict_type: The object type of the items in the dictionary. + :rtype: dict + """ + if isinstance(attr, list): + return {x["key"]: self.deserialize_data(x["value"], dict_type) for x in attr} + + if isinstance(attr, ET.Element): + # Transform value into {"Key": "value"} + attr = {el.tag: el.text for el in attr} + return {k: self.deserialize_data(v, dict_type) for k, v in attr.items()} + + def deserialize_object(self, attr, **kwargs): + """Deserialize a generic object. + This will be handled as a dictionary. + + :param dict attr: Dictionary to be deserialized. + :rtype: dict + :raises: TypeError if non-builtin datatype encountered. + """ + if attr is None: + return None + if isinstance(attr, ET.Element): + # Do no recurse on XML, just return the tree as-is + return attr + if isinstance(attr, basestring): + return self.deserialize_basic(attr, "str") + obj_type = type(attr) + if obj_type in self.basic_types: + return self.deserialize_basic(attr, self.basic_types[obj_type]) + if obj_type is _long_type: + return self.deserialize_long(attr) + + if obj_type == dict: + deserialized = {} + for key, value in attr.items(): + try: + deserialized[key] = self.deserialize_object(value, **kwargs) + except ValueError: + deserialized[key] = None + return deserialized + + if obj_type == list: + deserialized = [] + for obj in attr: + try: + deserialized.append(self.deserialize_object(obj, **kwargs)) + except ValueError: + pass + return deserialized + + else: + error = "Cannot deserialize generic object with type: " + raise TypeError(error + str(obj_type)) + + def deserialize_basic(self, attr, data_type): + """Deserialize basic builtin data type from string. + Will attempt to convert to str, int, float and bool. + This function will also accept '1', '0', 'true' and 'false' as + valid bool values. + + :param str attr: response string to be deserialized. + :param str data_type: deserialization data type. + :rtype: str, int, float or bool + :raises: TypeError if string format is not valid. + """ + # If we're here, data is supposed to be a basic type. + # If it's still an XML node, take the text + if isinstance(attr, ET.Element): + attr = attr.text + if not attr: + if data_type == "str": + # None or '', node is empty string. + return "" + else: + # None or '', node with a strong type is None. + # Don't try to model "empty bool" or "empty int" + return None + + if data_type == "bool": + if attr in [True, False, 1, 0]: + return bool(attr) + elif isinstance(attr, basestring): + if attr.lower() in ["true", "1"]: + return True + elif attr.lower() in ["false", "0"]: + return False + raise TypeError("Invalid boolean value: {}".format(attr)) + + if data_type == "str": + return self.deserialize_unicode(attr) + return eval(data_type)(attr) # nosec + + @staticmethod + def deserialize_unicode(data): + """Preserve unicode objects in Python 2, otherwise return data + as a string. + + :param str data: response string to be deserialized. + :rtype: str or unicode + """ + # We might be here because we have an enum modeled as string, + # and we try to deserialize a partial dict with enum inside + if isinstance(data, Enum): + return data + + # Consider this is real string + try: + if isinstance(data, unicode): + return data + except NameError: + return str(data) + else: + return str(data) + + @staticmethod + def deserialize_enum(data, enum_obj): + """Deserialize string into enum object. + + If the string is not a valid enum value it will be returned as-is + and a warning will be logged. + + :param str data: Response string to be deserialized. If this value is + None or invalid it will be returned as-is. + :param Enum enum_obj: Enum object to deserialize to. + :rtype: Enum + """ + if isinstance(data, enum_obj) or data is None: + return data + if isinstance(data, Enum): + 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: + error = "{!r} is not a valid index for enum {!r}" + raise DeserializationError(error.format(data, enum_obj)) + try: + return enum_obj(str(data)) + except ValueError: + for enum_value in enum_obj: + if enum_value.value.lower() == str(data).lower(): + return enum_value + # We don't fail anymore for unknown value, we deserialize as a string + _LOGGER.warning("Deserializer is not able to find %s as valid enum in %s", data, enum_obj) + return Deserializer.deserialize_unicode(data) + + @staticmethod + def deserialize_bytearray(attr): + """Deserialize string into bytearray. + + :param str attr: response string to be deserialized. + :rtype: bytearray + :raises: TypeError if string format invalid. + """ + if isinstance(attr, ET.Element): + attr = attr.text + return bytearray(b64decode(attr)) + + @staticmethod + def deserialize_base64(attr): + """Deserialize base64 encoded string into string. + + :param str attr: response string to be deserialized. + :rtype: bytearray + :raises: TypeError if string format invalid. + """ + if isinstance(attr, ET.Element): + attr = attr.text + padding = "=" * (3 - (len(attr) + 3) % 4) + attr = attr + padding + encoded = attr.replace("-", "+").replace("_", "/") + return b64decode(encoded) + + @staticmethod + def deserialize_decimal(attr): + """Deserialize string into Decimal object. + + :param str attr: response string to be deserialized. + :rtype: Decimal + :raises: DeserializationError if string format invalid. + """ + if isinstance(attr, ET.Element): + attr = attr.text + try: + return decimal.Decimal(attr) + except decimal.DecimalException as err: + msg = "Invalid decimal {}".format(attr) + raise_with_traceback(DeserializationError, msg, err) + + @staticmethod + def deserialize_long(attr): + """Deserialize string into long (Py2) or int (Py3). + + :param str attr: response string to be deserialized. + :rtype: long or int + :raises: ValueError if string format invalid. + """ + if isinstance(attr, ET.Element): + attr = attr.text + return _long_type(attr) + + @staticmethod + def deserialize_duration(attr): + """Deserialize ISO-8601 formatted string into TimeDelta object. + + :param str attr: response string to be deserialized. + :rtype: TimeDelta + :raises: DeserializationError if string format invalid. + """ + if isinstance(attr, ET.Element): + attr = attr.text + try: + duration = isodate.parse_duration(attr) + except (ValueError, OverflowError, AttributeError) as err: + msg = "Cannot deserialize duration object." + raise_with_traceback(DeserializationError, msg, err) + else: + return duration + + @staticmethod + def deserialize_date(attr): + """Deserialize ISO-8601 formatted string into Date object. + + :param str attr: response string to be deserialized. + :rtype: Date + :raises: DeserializationError if string format invalid. + """ + if isinstance(attr, ET.Element): + attr = attr.text + if re.search(r"[^\W\d_]", attr, re.I + re.U): + 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) + + @staticmethod + def deserialize_time(attr): + """Deserialize ISO-8601 formatted string into time object. + + :param str attr: response string to be deserialized. + :rtype: datetime.time + :raises: DeserializationError if string format invalid. + """ + if isinstance(attr, ET.Element): + attr = attr.text + if re.search(r"[^\W\d_]", attr, re.I + re.U): + raise DeserializationError("Date must have only digits and -. Received: %s" % attr) + return isodate.parse_time(attr) + + @staticmethod + def deserialize_rfc(attr): + """Deserialize RFC-1123 formatted string into Datetime object. + + :param str attr: response string to be deserialized. + :rtype: Datetime + :raises: DeserializationError if string format invalid. + """ + if isinstance(attr, ET.Element): + attr = attr.text + try: + parsed_date = email.utils.parsedate_tz(attr) + date_obj = datetime.datetime( + *parsed_date[:6], tzinfo=_FixedOffset(datetime.timedelta(minutes=(parsed_date[9] or 0) / 60)) + ) + if not date_obj.tzinfo: + 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) + else: + return date_obj + + @staticmethod + def deserialize_iso(attr): + """Deserialize ISO-8601 formatted string into Datetime object. + + :param str attr: response string to be deserialized. + :rtype: Datetime + :raises: DeserializationError if string format invalid. + """ + if isinstance(attr, ET.Element): + attr = attr.text + try: + attr = attr.upper() + match = Deserializer.valid_date.match(attr) + if not match: + raise ValueError("Invalid datetime string: " + attr) + + check_decimal = attr.split(".") + if len(check_decimal) > 1: + decimal_str = "" + for digit in check_decimal[1]: + if digit.isdigit(): + decimal_str += digit + else: + break + if len(decimal_str) > 6: + attr = attr.replace(decimal_str, decimal_str[0:6]) + + date_obj = isodate.parse_datetime(attr) + test_utc = date_obj.utctimetuple() + if test_utc.tm_year > 9999 or test_utc.tm_year < 1: + raise OverflowError("Hit max or min date") + except (ValueError, OverflowError, AttributeError) as err: + msg = "Cannot deserialize datetime object." + raise_with_traceback(DeserializationError, msg, err) + else: + return date_obj + + @staticmethod + def deserialize_unix(attr): + """Serialize Datetime object into IntTime format. + This is represented as seconds. + + :param int attr: Object to be serialized. + :rtype: Datetime + :raises: DeserializationError if format invalid + """ + if isinstance(attr, ET.Element): + attr = int(attr.text) + try: + 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) + else: + return date_obj diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_sql_management_client.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_sql_management_client.py index a6f3006ba5bc4..8ca559c87852f 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_sql_management_client.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_sql_management_client.py @@ -9,20 +9,149 @@ from copy import deepcopy from typing import Any, TYPE_CHECKING -from msrest import Deserializer, Serializer - from azure.core.rest import HttpRequest, HttpResponse from azure.mgmt.core import ARMPipelineClient from . import models from ._configuration import SqlManagementClientConfiguration -from .operations import BackupShortTermRetentionPoliciesOperations, CapabilitiesOperations, DataMaskingPoliciesOperations, DataMaskingRulesOperations, DataWarehouseUserActivitiesOperations, DatabaseAdvancedThreatProtectionSettingsOperations, DatabaseAdvisorsOperations, DatabaseAutomaticTuningOperations, DatabaseBlobAuditingPoliciesOperations, DatabaseColumnsOperations, DatabaseExtensionsOperations, DatabaseOperationsOperations, DatabaseRecommendedActionsOperations, DatabaseSchemasOperations, DatabaseSecurityAlertPoliciesOperations, DatabaseTablesOperations, DatabaseUsagesOperations, DatabaseVulnerabilityAssessmentRuleBaselinesOperations, DatabaseVulnerabilityAssessmentScansOperations, DatabaseVulnerabilityAssessmentsOperations, DatabasesOperations, DeletedServersOperations, DistributedAvailabilityGroupsOperations, ElasticPoolActivitiesOperations, ElasticPoolDatabaseActivitiesOperations, ElasticPoolOperationsOperations, ElasticPoolsOperations, EncryptionProtectorsOperations, EndpointCertificatesOperations, ExtendedDatabaseBlobAuditingPoliciesOperations, ExtendedServerBlobAuditingPoliciesOperations, FailoverGroupsOperations, FirewallRulesOperations, GeoBackupPoliciesOperations, IPv6FirewallRulesOperations, InstanceFailoverGroupsOperations, InstancePoolsOperations, JobAgentsOperations, JobCredentialsOperations, JobExecutionsOperations, JobStepExecutionsOperations, JobStepsOperations, JobTargetExecutionsOperations, JobTargetGroupsOperations, JobVersionsOperations, JobsOperations, LedgerDigestUploadsOperations, LongTermRetentionBackupsOperations, LongTermRetentionManagedInstanceBackupsOperations, LongTermRetentionPoliciesOperations, MaintenanceWindowOptionsOperations, MaintenanceWindowsOperations, ManagedBackupShortTermRetentionPoliciesOperations, ManagedDatabaseColumnsOperations, ManagedDatabaseQueriesOperations, ManagedDatabaseRecommendedSensitivityLabelsOperations, ManagedDatabaseRestoreDetailsOperations, ManagedDatabaseSchemasOperations, ManagedDatabaseSecurityAlertPoliciesOperations, ManagedDatabaseSecurityEventsOperations, ManagedDatabaseSensitivityLabelsOperations, ManagedDatabaseTablesOperations, ManagedDatabaseTransparentDataEncryptionOperations, ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations, ManagedDatabaseVulnerabilityAssessmentScansOperations, ManagedDatabaseVulnerabilityAssessmentsOperations, ManagedDatabasesOperations, ManagedInstanceAdministratorsOperations, ManagedInstanceAzureADOnlyAuthenticationsOperations, ManagedInstanceEncryptionProtectorsOperations, ManagedInstanceKeysOperations, ManagedInstanceLongTermRetentionPoliciesOperations, ManagedInstanceOperationsOperations, ManagedInstancePrivateEndpointConnectionsOperations, ManagedInstancePrivateLinkResourcesOperations, ManagedInstanceTdeCertificatesOperations, ManagedInstanceVulnerabilityAssessmentsOperations, ManagedInstancesOperations, ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations, ManagedServerDnsAliasesOperations, ManagedServerSecurityAlertPoliciesOperations, Operations, OutboundFirewallRulesOperations, PrivateEndpointConnectionsOperations, PrivateLinkResourcesOperations, RecommendedSensitivityLabelsOperations, RecoverableDatabasesOperations, RecoverableManagedDatabasesOperations, ReplicationLinksOperations, RestorableDroppedDatabasesOperations, RestorableDroppedManagedDatabasesOperations, RestorePointsOperations, SensitivityLabelsOperations, ServerAdvancedThreatProtectionSettingsOperations, ServerAdvisorsOperations, ServerAutomaticTuningOperations, ServerAzureADAdministratorsOperations, ServerAzureADOnlyAuthenticationsOperations, ServerBlobAuditingPoliciesOperations, ServerCommunicationLinksOperations, ServerConnectionPoliciesOperations, ServerDevOpsAuditSettingsOperations, ServerDnsAliasesOperations, ServerKeysOperations, ServerOperationsOperations, ServerSecurityAlertPoliciesOperations, ServerTrustCertificatesOperations, ServerTrustGroupsOperations, ServerUsagesOperations, ServerVulnerabilityAssessmentsOperations, ServersOperations, ServiceObjectivesOperations, SqlAgentOperations, SubscriptionUsagesOperations, SyncAgentsOperations, SyncGroupsOperations, SyncMembersOperations, TdeCertificatesOperations, TimeZonesOperations, TransparentDataEncryptionsOperations, UsagesOperations, VirtualClustersOperations, VirtualNetworkRulesOperations, WorkloadClassifiersOperations, WorkloadGroupsOperations +from ._serialization import Deserializer, Serializer +from .operations import ( + BackupShortTermRetentionPoliciesOperations, + CapabilitiesOperations, + DataMaskingPoliciesOperations, + DataMaskingRulesOperations, + DataWarehouseUserActivitiesOperations, + DatabaseAdvancedThreatProtectionSettingsOperations, + DatabaseAdvisorsOperations, + DatabaseAutomaticTuningOperations, + DatabaseBlobAuditingPoliciesOperations, + DatabaseColumnsOperations, + DatabaseExtensionsOperations, + DatabaseOperationsOperations, + DatabaseRecommendedActionsOperations, + DatabaseSchemasOperations, + DatabaseSecurityAlertPoliciesOperations, + DatabaseTablesOperations, + DatabaseUsagesOperations, + DatabaseVulnerabilityAssessmentRuleBaselinesOperations, + DatabaseVulnerabilityAssessmentScansOperations, + DatabaseVulnerabilityAssessmentsOperations, + DatabasesOperations, + DeletedServersOperations, + DistributedAvailabilityGroupsOperations, + ElasticPoolActivitiesOperations, + ElasticPoolDatabaseActivitiesOperations, + ElasticPoolOperationsOperations, + ElasticPoolsOperations, + EncryptionProtectorsOperations, + EndpointCertificatesOperations, + ExtendedDatabaseBlobAuditingPoliciesOperations, + ExtendedServerBlobAuditingPoliciesOperations, + FailoverGroupsOperations, + FirewallRulesOperations, + GeoBackupPoliciesOperations, + IPv6FirewallRulesOperations, + InstanceFailoverGroupsOperations, + InstancePoolsOperations, + JobAgentsOperations, + JobCredentialsOperations, + JobExecutionsOperations, + JobStepExecutionsOperations, + JobStepsOperations, + JobTargetExecutionsOperations, + JobTargetGroupsOperations, + JobVersionsOperations, + JobsOperations, + LedgerDigestUploadsOperations, + LongTermRetentionBackupsOperations, + LongTermRetentionManagedInstanceBackupsOperations, + LongTermRetentionPoliciesOperations, + MaintenanceWindowOptionsOperations, + MaintenanceWindowsOperations, + ManagedBackupShortTermRetentionPoliciesOperations, + ManagedDatabaseAdvancedThreatProtectionSettingsOperations, + ManagedDatabaseColumnsOperations, + ManagedDatabaseQueriesOperations, + ManagedDatabaseRecommendedSensitivityLabelsOperations, + ManagedDatabaseRestoreDetailsOperations, + ManagedDatabaseSchemasOperations, + ManagedDatabaseSecurityAlertPoliciesOperations, + ManagedDatabaseSecurityEventsOperations, + ManagedDatabaseSensitivityLabelsOperations, + ManagedDatabaseTablesOperations, + ManagedDatabaseTransparentDataEncryptionOperations, + ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations, + ManagedDatabaseVulnerabilityAssessmentScansOperations, + ManagedDatabaseVulnerabilityAssessmentsOperations, + ManagedDatabasesOperations, + ManagedInstanceAdministratorsOperations, + ManagedInstanceAdvancedThreatProtectionSettingsOperations, + ManagedInstanceAzureADOnlyAuthenticationsOperations, + ManagedInstanceDtcsOperations, + ManagedInstanceEncryptionProtectorsOperations, + ManagedInstanceKeysOperations, + ManagedInstanceLongTermRetentionPoliciesOperations, + ManagedInstanceOperationsOperations, + ManagedInstancePrivateEndpointConnectionsOperations, + ManagedInstancePrivateLinkResourcesOperations, + ManagedInstanceTdeCertificatesOperations, + ManagedInstanceVulnerabilityAssessmentsOperations, + ManagedInstancesOperations, + ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations, + ManagedServerDnsAliasesOperations, + ManagedServerSecurityAlertPoliciesOperations, + Operations, + OutboundFirewallRulesOperations, + PrivateEndpointConnectionsOperations, + PrivateLinkResourcesOperations, + RecommendedSensitivityLabelsOperations, + RecoverableDatabasesOperations, + RecoverableManagedDatabasesOperations, + ReplicationLinksOperations, + RestorableDroppedDatabasesOperations, + RestorableDroppedManagedDatabasesOperations, + RestorePointsOperations, + SensitivityLabelsOperations, + ServerAdvancedThreatProtectionSettingsOperations, + ServerAdvisorsOperations, + ServerAutomaticTuningOperations, + ServerAzureADAdministratorsOperations, + ServerAzureADOnlyAuthenticationsOperations, + ServerBlobAuditingPoliciesOperations, + ServerCommunicationLinksOperations, + ServerConnectionPoliciesOperations, + ServerDevOpsAuditSettingsOperations, + ServerDnsAliasesOperations, + ServerKeysOperations, + ServerOperationsOperations, + ServerSecurityAlertPoliciesOperations, + ServerTrustCertificatesOperations, + ServerTrustGroupsOperations, + ServerUsagesOperations, + ServerVulnerabilityAssessmentsOperations, + ServersOperations, + ServiceObjectivesOperations, + SqlAgentOperations, + SubscriptionUsagesOperations, + SyncAgentsOperations, + SyncGroupsOperations, + SyncMembersOperations, + TdeCertificatesOperations, + TimeZonesOperations, + TransparentDataEncryptionsOperations, + UsagesOperations, + VirtualClustersOperations, + VirtualNetworkRulesOperations, + WorkloadClassifiersOperations, + WorkloadGroupsOperations, +) if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports from azure.core.credentials import TokenCredential -class SqlManagementClient: # pylint: disable=too-many-instance-attributes + +class SqlManagementClient: # pylint: disable=client-accepts-api-version-keyword,too-many-instance-attributes """The Azure SQL Database management API provides a RESTful set of web services that interact with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, update, and delete databases. @@ -131,11 +260,6 @@ class SqlManagementClient: # pylint: disable=too-many-instance-attributes :vartype managed_database_columns: azure.mgmt.sql.operations.ManagedDatabaseColumnsOperations :ivar managed_database_queries: ManagedDatabaseQueriesOperations operations :vartype managed_database_queries: azure.mgmt.sql.operations.ManagedDatabaseQueriesOperations - :ivar managed_database_restore_details: ManagedDatabaseRestoreDetailsOperations operations - :vartype managed_database_restore_details: - azure.mgmt.sql.operations.ManagedDatabaseRestoreDetailsOperations - :ivar managed_databases: ManagedDatabasesOperations operations - :vartype managed_databases: azure.mgmt.sql.operations.ManagedDatabasesOperations :ivar managed_database_schemas: ManagedDatabaseSchemasOperations operations :vartype managed_database_schemas: azure.mgmt.sql.operations.ManagedDatabaseSchemasOperations :ivar managed_database_security_alert_policies: ManagedDatabaseSecurityAlertPoliciesOperations @@ -317,8 +441,6 @@ class SqlManagementClient: # pylint: disable=too-many-instance-attributes :vartype ipv6_firewall_rules: azure.mgmt.sql.operations.IPv6FirewallRulesOperations :ivar endpoint_certificates: EndpointCertificatesOperations operations :vartype endpoint_certificates: azure.mgmt.sql.operations.EndpointCertificatesOperations - :ivar replication_links: ReplicationLinksOperations operations - :vartype replication_links: azure.mgmt.sql.operations.ReplicationLinksOperations :ivar managed_database_sensitivity_labels: ManagedDatabaseSensitivityLabelsOperations operations :vartype managed_database_sensitivity_labels: @@ -357,9 +479,26 @@ class SqlManagementClient: # pylint: disable=too-many-instance-attributes :ivar managed_server_dns_aliases: ManagedServerDnsAliasesOperations operations :vartype managed_server_dns_aliases: azure.mgmt.sql.operations.ManagedServerDnsAliasesOperations - :param credential: Credential needed for the client to connect to Azure. + :ivar managed_instance_dtcs: ManagedInstanceDtcsOperations operations + :vartype managed_instance_dtcs: azure.mgmt.sql.operations.ManagedInstanceDtcsOperations + :ivar managed_database_advanced_threat_protection_settings: + ManagedDatabaseAdvancedThreatProtectionSettingsOperations operations + :vartype managed_database_advanced_threat_protection_settings: + azure.mgmt.sql.operations.ManagedDatabaseAdvancedThreatProtectionSettingsOperations + :ivar managed_instance_advanced_threat_protection_settings: + ManagedInstanceAdvancedThreatProtectionSettingsOperations operations + :vartype managed_instance_advanced_threat_protection_settings: + azure.mgmt.sql.operations.ManagedInstanceAdvancedThreatProtectionSettingsOperations + :ivar replication_links: ReplicationLinksOperations operations + :vartype replication_links: azure.mgmt.sql.operations.ReplicationLinksOperations + :ivar managed_database_restore_details: ManagedDatabaseRestoreDetailsOperations operations + :vartype managed_database_restore_details: + azure.mgmt.sql.operations.ManagedDatabaseRestoreDetailsOperations + :ivar managed_databases: ManagedDatabasesOperations operations + :vartype managed_databases: azure.mgmt.sql.operations.ManagedDatabasesOperations + :param credential: Credential needed for the client to connect to Azure. Required. :type credential: ~azure.core.credentials.TokenCredential - :param subscription_id: The subscription ID that identifies an Azure subscription. + :param subscription_id: The subscription ID that identifies an Azure subscription. Required. :type subscription_id: str :param base_url: Service URL. Default value is "https://management.azure.com". :type base_url: str @@ -374,7 +513,9 @@ def __init__( base_url: str = "https://management.azure.com", **kwargs: Any ) -> None: - self._config = SqlManagementClientConfiguration(credential=credential, subscription_id=subscription_id, **kwargs) + self._config = SqlManagementClientConfiguration( + 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)} @@ -393,12 +534,8 @@ def __init__( self.geo_backup_policies = GeoBackupPoliciesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.databases = DatabasesOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.elastic_pools = ElasticPoolsOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.databases = DatabasesOperations(self._client, self._config, self._serialize, self._deserialize) + self.elastic_pools = ElasticPoolsOperations(self._client, self._config, self._serialize, self._deserialize) self.server_communication_links = ServerCommunicationLinksOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -411,9 +548,7 @@ def __init__( self.elastic_pool_database_activities = ElasticPoolDatabaseActivitiesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.server_usages = ServerUsagesOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.server_usages = ServerUsagesOperations(self._client, self._config, self._serialize, self._deserialize) self.database_advisors = DatabaseAdvisorsOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -432,9 +567,7 @@ def __init__( self.database_security_alert_policies = DatabaseSecurityAlertPoliciesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.database_tables = DatabaseTablesOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.database_tables = DatabaseTablesOperations(self._client, self._config, self._serialize, self._deserialize) self.database_vulnerability_assessment_rule_baselines = DatabaseVulnerabilityAssessmentRuleBaselinesOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -447,57 +580,35 @@ def __init__( self.data_warehouse_user_activities = DataWarehouseUserActivitiesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.deleted_servers = DeletedServersOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.deleted_servers = DeletedServersOperations(self._client, self._config, self._serialize, self._deserialize) self.elastic_pool_operations = ElasticPoolOperationsOperations( self._client, self._config, self._serialize, self._deserialize ) self.encryption_protectors = EncryptionProtectorsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.failover_groups = FailoverGroupsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.firewall_rules = FirewallRulesOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.failover_groups = FailoverGroupsOperations(self._client, self._config, self._serialize, self._deserialize) + self.firewall_rules = FirewallRulesOperations(self._client, self._config, self._serialize, self._deserialize) self.instance_failover_groups = InstanceFailoverGroupsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.instance_pools = InstancePoolsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.job_agents = JobAgentsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.job_credentials = JobCredentialsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.job_executions = JobExecutionsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.jobs = JobsOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.instance_pools = InstancePoolsOperations(self._client, self._config, self._serialize, self._deserialize) + self.job_agents = JobAgentsOperations(self._client, self._config, self._serialize, self._deserialize) + self.job_credentials = JobCredentialsOperations(self._client, self._config, self._serialize, self._deserialize) + self.job_executions = JobExecutionsOperations(self._client, self._config, self._serialize, self._deserialize) + self.jobs = JobsOperations(self._client, self._config, self._serialize, self._deserialize) self.job_step_executions = JobStepExecutionsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.job_steps = JobStepsOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.job_steps = JobStepsOperations(self._client, self._config, self._serialize, self._deserialize) self.job_target_executions = JobTargetExecutionsOperations( self._client, self._config, self._serialize, self._deserialize ) self.job_target_groups = JobTargetGroupsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.job_versions = JobVersionsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.capabilities = CapabilitiesOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.job_versions = JobVersionsOperations(self._client, self._config, self._serialize, self._deserialize) + self.capabilities = CapabilitiesOperations(self._client, self._config, self._serialize, self._deserialize) self.long_term_retention_policies = LongTermRetentionPoliciesOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -516,12 +627,6 @@ def __init__( self.managed_database_queries = ManagedDatabaseQueriesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.managed_database_restore_details = ManagedDatabaseRestoreDetailsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.managed_databases = ManagedDatabasesOperations( - self._client, self._config, self._serialize, self._deserialize - ) self.managed_database_schemas = ManagedDatabaseSchemasOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -537,8 +642,10 @@ def __init__( self.managed_database_transparent_data_encryption = ManagedDatabaseTransparentDataEncryptionOperations( self._client, self._config, self._serialize, self._deserialize ) - self.managed_database_vulnerability_assessment_rule_baselines = ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations( - self._client, self._config, self._serialize, self._deserialize + self.managed_database_vulnerability_assessment_rule_baselines = ( + ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations( + self._client, self._config, self._serialize, self._deserialize + ) ) self.managed_database_vulnerability_assessments = ManagedDatabaseVulnerabilityAssessmentsOperations( self._client, self._config, self._serialize, self._deserialize @@ -576,15 +683,15 @@ def __init__( self.managed_instance_vulnerability_assessments = ManagedInstanceVulnerabilityAssessmentsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.managed_restorable_dropped_database_backup_short_term_retention_policies = ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations( - self._client, self._config, self._serialize, self._deserialize + self.managed_restorable_dropped_database_backup_short_term_retention_policies = ( + ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations( + self._client, self._config, self._serialize, self._deserialize + ) ) self.managed_server_security_alert_policies = ManagedServerSecurityAlertPoliciesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.operations = Operations( - self._client, self._config, self._serialize, self._deserialize - ) + self.operations = Operations(self._client, self._config, self._serialize, self._deserialize) self.private_endpoint_connections = PrivateEndpointConnectionsOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -594,12 +701,8 @@ def __init__( self.recoverable_managed_databases = RecoverableManagedDatabasesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.restore_points = RestorePointsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.server_advisors = ServerAdvisorsOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.restore_points = RestorePointsOperations(self._client, self._config, self._serialize, self._deserialize) + self.server_advisors = ServerAdvisorsOperations(self._client, self._config, self._serialize, self._deserialize) self.server_automatic_tuning = ServerAutomaticTuningOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -615,9 +718,7 @@ def __init__( self.server_dns_aliases = ServerDnsAliasesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.server_keys = ServerKeysOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.server_keys = ServerKeysOperations(self._client, self._config, self._serialize, self._deserialize) self.server_operations = ServerOperationsOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -630,27 +731,17 @@ def __init__( self.server_vulnerability_assessments = ServerVulnerabilityAssessmentsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.sql_agent = SqlAgentOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.sql_agent = SqlAgentOperations(self._client, self._config, self._serialize, self._deserialize) self.subscription_usages = SubscriptionUsagesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.sync_agents = SyncAgentsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.sync_groups = SyncGroupsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.sync_members = SyncMembersOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.sync_agents = SyncAgentsOperations(self._client, self._config, self._serialize, self._deserialize) + self.sync_groups = SyncGroupsOperations(self._client, self._config, self._serialize, self._deserialize) + self.sync_members = SyncMembersOperations(self._client, self._config, self._serialize, self._deserialize) self.tde_certificates = TdeCertificatesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.time_zones = TimeZonesOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.time_zones = TimeZonesOperations(self._client, self._config, self._serialize, self._deserialize) self.virtual_clusters = VirtualClustersOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -660,9 +751,7 @@ def __init__( self.workload_classifiers = WorkloadClassifiersOperations( self._client, self._config, self._serialize, self._deserialize ) - self.workload_groups = WorkloadGroupsOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.workload_groups = WorkloadGroupsOperations(self._client, self._config, self._serialize, self._deserialize) self.transparent_data_encryptions = TransparentDataEncryptionsOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -675,21 +764,15 @@ def __init__( self.database_operations = DatabaseOperationsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.database_usages = DatabaseUsagesOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.database_usages = DatabaseUsagesOperations(self._client, self._config, self._serialize, self._deserialize) self.ledger_digest_uploads = LedgerDigestUploadsOperations( self._client, self._config, self._serialize, self._deserialize ) self.outbound_firewall_rules = OutboundFirewallRulesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.servers = ServersOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.usages = UsagesOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.servers = ServersOperations(self._client, self._config, self._serialize, self._deserialize) + self.usages = UsagesOperations(self._client, self._config, self._serialize, self._deserialize) self.long_term_retention_backups = LongTermRetentionBackupsOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -720,9 +803,6 @@ def __init__( self.endpoint_certificates = EndpointCertificatesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.replication_links = ReplicationLinksOperations( - self._client, self._config, self._serialize, self._deserialize - ) self.managed_database_sensitivity_labels = ManagedDatabaseSensitivityLabelsOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -756,13 +836,30 @@ def __init__( self.managed_server_dns_aliases = ManagedServerDnsAliasesOperations( self._client, self._config, self._serialize, self._deserialize ) + self.managed_instance_dtcs = ManagedInstanceDtcsOperations( + self._client, self._config, self._serialize, self._deserialize + ) + self.managed_database_advanced_threat_protection_settings = ( + ManagedDatabaseAdvancedThreatProtectionSettingsOperations( + self._client, self._config, self._serialize, self._deserialize + ) + ) + self.managed_instance_advanced_threat_protection_settings = ( + ManagedInstanceAdvancedThreatProtectionSettingsOperations( + self._client, self._config, self._serialize, self._deserialize + ) + ) + self.replication_links = ReplicationLinksOperations( + self._client, self._config, self._serialize, self._deserialize + ) + self.managed_database_restore_details = ManagedDatabaseRestoreDetailsOperations( + self._client, self._config, self._serialize, self._deserialize + ) + self.managed_databases = ManagedDatabasesOperations( + self._client, self._config, self._serialize, self._deserialize + ) - - def _send_request( - self, - request: HttpRequest, - **kwargs: Any - ) -> HttpResponse: + def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: """Runs the network request through the client's chained policies. >>> from azure.core.rest import HttpRequest @@ -771,7 +868,7 @@ def _send_request( >>> response = client._send_request(request) - For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart + For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request :param request: The network request you want to make. Required. :type request: ~azure.core.rest.HttpRequest diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_vendor.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_vendor.py index 138f663c53a4e..9aad73fc743e7 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_vendor.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_vendor.py @@ -7,6 +7,7 @@ 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) @@ -14,6 +15,7 @@ def _convert_request(request, files=None): request.set_formdata_body(files) return request + def _format_url_section(template, **kwargs): components = template.split("/") while components: @@ -21,7 +23,5 @@ def _format_url_section(template, **kwargs): 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 - ] + components = [c for c in formatted_components if "{}".format(key.args[0]) not in c] template = "/".join(components) diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_version.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_version.py index 0cc2e55e6243b..c78e629b6f086 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_version.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "4.0.0b3" +VERSION = "0.9.0" diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/__init__.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/__init__.py index 176c97d501a3b..36103f764e367 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/__init__.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/__init__.py @@ -14,7 +14,8 @@ except ImportError: _patch_all = [] from ._patch import patch_sdk as _patch_sdk -__all__ = ['SqlManagementClient'] + +__all__ = ["SqlManagementClient"] __all__.extend([p for p in _patch_all if p not in __all__]) _patch_sdk() diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/_configuration.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/_configuration.py index 85e6ab69a7a13..dd110fbdd0911 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/_configuration.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/_configuration.py @@ -25,18 +25,13 @@ class SqlManagementClientConfiguration(Configuration): # pylint: disable=too-ma Note that all parameters used to create this instance are saved as instance attributes. - :param credential: Credential needed for the client to connect to Azure. + :param credential: Credential needed for the client to connect to Azure. Required. :type credential: ~azure.core.credentials_async.AsyncTokenCredential - :param subscription_id: The subscription ID that identifies an Azure subscription. + :param subscription_id: The subscription ID that identifies an Azure subscription. Required. :type subscription_id: str """ - def __init__( - self, - credential: "AsyncTokenCredential", - subscription_id: str, - **kwargs: Any - ) -> None: + def __init__(self, credential: "AsyncTokenCredential", subscription_id: str, **kwargs: Any) -> None: super(SqlManagementClientConfiguration, self).__init__(**kwargs) if credential is None: raise ValueError("Parameter 'credential' must not be None.") @@ -45,22 +40,21 @@ def __init__( self.credential = credential self.subscription_id = subscription_id - self.credential_scopes = kwargs.pop('credential_scopes', ['https://management.azure.com/.default']) - kwargs.setdefault('sdk_moniker', 'mgmt-sql/{}'.format(VERSION)) + self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) + kwargs.setdefault("sdk_moniker", "mgmt-sql/{}".format(VERSION)) self._configure(**kwargs) - 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.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.authentication_policy = kwargs.get('authentication_policy') + 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.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.authentication_policy = kwargs.get("authentication_policy") if self.credential and not self.authentication_policy: - self.authentication_policy = AsyncARMChallengeAuthenticationPolicy(self.credential, *self.credential_scopes, **kwargs) + self.authentication_policy = AsyncARMChallengeAuthenticationPolicy( + self.credential, *self.credential_scopes, **kwargs + ) diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/_patch.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/_patch.py index 74e48ecd07cf3..f99e77fef9861 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/_patch.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/_patch.py @@ -28,4 +28,4 @@ # This file is used for handwritten extensions to the generated code. Example: # https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md def patch_sdk(): - pass \ No newline at end of file + pass diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/_sql_management_client.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/_sql_management_client.py index 7661fedb80a82..766fb533d8f33 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/_sql_management_client.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/_sql_management_client.py @@ -9,20 +9,149 @@ from copy import deepcopy from typing import Any, Awaitable, TYPE_CHECKING -from msrest import Deserializer, Serializer - from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.mgmt.core import AsyncARMPipelineClient from .. import models +from .._serialization import Deserializer, Serializer from ._configuration import SqlManagementClientConfiguration -from .operations import BackupShortTermRetentionPoliciesOperations, CapabilitiesOperations, DataMaskingPoliciesOperations, DataMaskingRulesOperations, DataWarehouseUserActivitiesOperations, DatabaseAdvancedThreatProtectionSettingsOperations, DatabaseAdvisorsOperations, DatabaseAutomaticTuningOperations, DatabaseBlobAuditingPoliciesOperations, DatabaseColumnsOperations, DatabaseExtensionsOperations, DatabaseOperationsOperations, DatabaseRecommendedActionsOperations, DatabaseSchemasOperations, DatabaseSecurityAlertPoliciesOperations, DatabaseTablesOperations, DatabaseUsagesOperations, DatabaseVulnerabilityAssessmentRuleBaselinesOperations, DatabaseVulnerabilityAssessmentScansOperations, DatabaseVulnerabilityAssessmentsOperations, DatabasesOperations, DeletedServersOperations, DistributedAvailabilityGroupsOperations, ElasticPoolActivitiesOperations, ElasticPoolDatabaseActivitiesOperations, ElasticPoolOperationsOperations, ElasticPoolsOperations, EncryptionProtectorsOperations, EndpointCertificatesOperations, ExtendedDatabaseBlobAuditingPoliciesOperations, ExtendedServerBlobAuditingPoliciesOperations, FailoverGroupsOperations, FirewallRulesOperations, GeoBackupPoliciesOperations, IPv6FirewallRulesOperations, InstanceFailoverGroupsOperations, InstancePoolsOperations, JobAgentsOperations, JobCredentialsOperations, JobExecutionsOperations, JobStepExecutionsOperations, JobStepsOperations, JobTargetExecutionsOperations, JobTargetGroupsOperations, JobVersionsOperations, JobsOperations, LedgerDigestUploadsOperations, LongTermRetentionBackupsOperations, LongTermRetentionManagedInstanceBackupsOperations, LongTermRetentionPoliciesOperations, MaintenanceWindowOptionsOperations, MaintenanceWindowsOperations, ManagedBackupShortTermRetentionPoliciesOperations, ManagedDatabaseColumnsOperations, ManagedDatabaseQueriesOperations, ManagedDatabaseRecommendedSensitivityLabelsOperations, ManagedDatabaseRestoreDetailsOperations, ManagedDatabaseSchemasOperations, ManagedDatabaseSecurityAlertPoliciesOperations, ManagedDatabaseSecurityEventsOperations, ManagedDatabaseSensitivityLabelsOperations, ManagedDatabaseTablesOperations, ManagedDatabaseTransparentDataEncryptionOperations, ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations, ManagedDatabaseVulnerabilityAssessmentScansOperations, ManagedDatabaseVulnerabilityAssessmentsOperations, ManagedDatabasesOperations, ManagedInstanceAdministratorsOperations, ManagedInstanceAzureADOnlyAuthenticationsOperations, ManagedInstanceEncryptionProtectorsOperations, ManagedInstanceKeysOperations, ManagedInstanceLongTermRetentionPoliciesOperations, ManagedInstanceOperationsOperations, ManagedInstancePrivateEndpointConnectionsOperations, ManagedInstancePrivateLinkResourcesOperations, ManagedInstanceTdeCertificatesOperations, ManagedInstanceVulnerabilityAssessmentsOperations, ManagedInstancesOperations, ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations, ManagedServerDnsAliasesOperations, ManagedServerSecurityAlertPoliciesOperations, Operations, OutboundFirewallRulesOperations, PrivateEndpointConnectionsOperations, PrivateLinkResourcesOperations, RecommendedSensitivityLabelsOperations, RecoverableDatabasesOperations, RecoverableManagedDatabasesOperations, ReplicationLinksOperations, RestorableDroppedDatabasesOperations, RestorableDroppedManagedDatabasesOperations, RestorePointsOperations, SensitivityLabelsOperations, ServerAdvancedThreatProtectionSettingsOperations, ServerAdvisorsOperations, ServerAutomaticTuningOperations, ServerAzureADAdministratorsOperations, ServerAzureADOnlyAuthenticationsOperations, ServerBlobAuditingPoliciesOperations, ServerCommunicationLinksOperations, ServerConnectionPoliciesOperations, ServerDevOpsAuditSettingsOperations, ServerDnsAliasesOperations, ServerKeysOperations, ServerOperationsOperations, ServerSecurityAlertPoliciesOperations, ServerTrustCertificatesOperations, ServerTrustGroupsOperations, ServerUsagesOperations, ServerVulnerabilityAssessmentsOperations, ServersOperations, ServiceObjectivesOperations, SqlAgentOperations, SubscriptionUsagesOperations, SyncAgentsOperations, SyncGroupsOperations, SyncMembersOperations, TdeCertificatesOperations, TimeZonesOperations, TransparentDataEncryptionsOperations, UsagesOperations, VirtualClustersOperations, VirtualNetworkRulesOperations, WorkloadClassifiersOperations, WorkloadGroupsOperations +from .operations import ( + BackupShortTermRetentionPoliciesOperations, + CapabilitiesOperations, + DataMaskingPoliciesOperations, + DataMaskingRulesOperations, + DataWarehouseUserActivitiesOperations, + DatabaseAdvancedThreatProtectionSettingsOperations, + DatabaseAdvisorsOperations, + DatabaseAutomaticTuningOperations, + DatabaseBlobAuditingPoliciesOperations, + DatabaseColumnsOperations, + DatabaseExtensionsOperations, + DatabaseOperationsOperations, + DatabaseRecommendedActionsOperations, + DatabaseSchemasOperations, + DatabaseSecurityAlertPoliciesOperations, + DatabaseTablesOperations, + DatabaseUsagesOperations, + DatabaseVulnerabilityAssessmentRuleBaselinesOperations, + DatabaseVulnerabilityAssessmentScansOperations, + DatabaseVulnerabilityAssessmentsOperations, + DatabasesOperations, + DeletedServersOperations, + DistributedAvailabilityGroupsOperations, + ElasticPoolActivitiesOperations, + ElasticPoolDatabaseActivitiesOperations, + ElasticPoolOperationsOperations, + ElasticPoolsOperations, + EncryptionProtectorsOperations, + EndpointCertificatesOperations, + ExtendedDatabaseBlobAuditingPoliciesOperations, + ExtendedServerBlobAuditingPoliciesOperations, + FailoverGroupsOperations, + FirewallRulesOperations, + GeoBackupPoliciesOperations, + IPv6FirewallRulesOperations, + InstanceFailoverGroupsOperations, + InstancePoolsOperations, + JobAgentsOperations, + JobCredentialsOperations, + JobExecutionsOperations, + JobStepExecutionsOperations, + JobStepsOperations, + JobTargetExecutionsOperations, + JobTargetGroupsOperations, + JobVersionsOperations, + JobsOperations, + LedgerDigestUploadsOperations, + LongTermRetentionBackupsOperations, + LongTermRetentionManagedInstanceBackupsOperations, + LongTermRetentionPoliciesOperations, + MaintenanceWindowOptionsOperations, + MaintenanceWindowsOperations, + ManagedBackupShortTermRetentionPoliciesOperations, + ManagedDatabaseAdvancedThreatProtectionSettingsOperations, + ManagedDatabaseColumnsOperations, + ManagedDatabaseQueriesOperations, + ManagedDatabaseRecommendedSensitivityLabelsOperations, + ManagedDatabaseRestoreDetailsOperations, + ManagedDatabaseSchemasOperations, + ManagedDatabaseSecurityAlertPoliciesOperations, + ManagedDatabaseSecurityEventsOperations, + ManagedDatabaseSensitivityLabelsOperations, + ManagedDatabaseTablesOperations, + ManagedDatabaseTransparentDataEncryptionOperations, + ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations, + ManagedDatabaseVulnerabilityAssessmentScansOperations, + ManagedDatabaseVulnerabilityAssessmentsOperations, + ManagedDatabasesOperations, + ManagedInstanceAdministratorsOperations, + ManagedInstanceAdvancedThreatProtectionSettingsOperations, + ManagedInstanceAzureADOnlyAuthenticationsOperations, + ManagedInstanceDtcsOperations, + ManagedInstanceEncryptionProtectorsOperations, + ManagedInstanceKeysOperations, + ManagedInstanceLongTermRetentionPoliciesOperations, + ManagedInstanceOperationsOperations, + ManagedInstancePrivateEndpointConnectionsOperations, + ManagedInstancePrivateLinkResourcesOperations, + ManagedInstanceTdeCertificatesOperations, + ManagedInstanceVulnerabilityAssessmentsOperations, + ManagedInstancesOperations, + ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations, + ManagedServerDnsAliasesOperations, + ManagedServerSecurityAlertPoliciesOperations, + Operations, + OutboundFirewallRulesOperations, + PrivateEndpointConnectionsOperations, + PrivateLinkResourcesOperations, + RecommendedSensitivityLabelsOperations, + RecoverableDatabasesOperations, + RecoverableManagedDatabasesOperations, + ReplicationLinksOperations, + RestorableDroppedDatabasesOperations, + RestorableDroppedManagedDatabasesOperations, + RestorePointsOperations, + SensitivityLabelsOperations, + ServerAdvancedThreatProtectionSettingsOperations, + ServerAdvisorsOperations, + ServerAutomaticTuningOperations, + ServerAzureADAdministratorsOperations, + ServerAzureADOnlyAuthenticationsOperations, + ServerBlobAuditingPoliciesOperations, + ServerCommunicationLinksOperations, + ServerConnectionPoliciesOperations, + ServerDevOpsAuditSettingsOperations, + ServerDnsAliasesOperations, + ServerKeysOperations, + ServerOperationsOperations, + ServerSecurityAlertPoliciesOperations, + ServerTrustCertificatesOperations, + ServerTrustGroupsOperations, + ServerUsagesOperations, + ServerVulnerabilityAssessmentsOperations, + ServersOperations, + ServiceObjectivesOperations, + SqlAgentOperations, + SubscriptionUsagesOperations, + SyncAgentsOperations, + SyncGroupsOperations, + SyncMembersOperations, + TdeCertificatesOperations, + TimeZonesOperations, + TransparentDataEncryptionsOperations, + UsagesOperations, + VirtualClustersOperations, + VirtualNetworkRulesOperations, + WorkloadClassifiersOperations, + WorkloadGroupsOperations, +) if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports from azure.core.credentials_async import AsyncTokenCredential -class SqlManagementClient: # pylint: disable=too-many-instance-attributes + +class SqlManagementClient: # pylint: disable=client-accepts-api-version-keyword,too-many-instance-attributes """The Azure SQL Database management API provides a RESTful set of web services that interact with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, update, and delete databases. @@ -135,11 +264,6 @@ class SqlManagementClient: # pylint: disable=too-many-instance-attributes :ivar managed_database_queries: ManagedDatabaseQueriesOperations operations :vartype managed_database_queries: azure.mgmt.sql.aio.operations.ManagedDatabaseQueriesOperations - :ivar managed_database_restore_details: ManagedDatabaseRestoreDetailsOperations operations - :vartype managed_database_restore_details: - azure.mgmt.sql.aio.operations.ManagedDatabaseRestoreDetailsOperations - :ivar managed_databases: ManagedDatabasesOperations operations - :vartype managed_databases: azure.mgmt.sql.aio.operations.ManagedDatabasesOperations :ivar managed_database_schemas: ManagedDatabaseSchemasOperations operations :vartype managed_database_schemas: azure.mgmt.sql.aio.operations.ManagedDatabaseSchemasOperations @@ -323,8 +447,6 @@ class SqlManagementClient: # pylint: disable=too-many-instance-attributes :vartype ipv6_firewall_rules: azure.mgmt.sql.aio.operations.IPv6FirewallRulesOperations :ivar endpoint_certificates: EndpointCertificatesOperations operations :vartype endpoint_certificates: azure.mgmt.sql.aio.operations.EndpointCertificatesOperations - :ivar replication_links: ReplicationLinksOperations operations - :vartype replication_links: azure.mgmt.sql.aio.operations.ReplicationLinksOperations :ivar managed_database_sensitivity_labels: ManagedDatabaseSensitivityLabelsOperations operations :vartype managed_database_sensitivity_labels: @@ -363,9 +485,26 @@ class SqlManagementClient: # pylint: disable=too-many-instance-attributes :ivar managed_server_dns_aliases: ManagedServerDnsAliasesOperations operations :vartype managed_server_dns_aliases: azure.mgmt.sql.aio.operations.ManagedServerDnsAliasesOperations - :param credential: Credential needed for the client to connect to Azure. + :ivar managed_instance_dtcs: ManagedInstanceDtcsOperations operations + :vartype managed_instance_dtcs: azure.mgmt.sql.aio.operations.ManagedInstanceDtcsOperations + :ivar managed_database_advanced_threat_protection_settings: + ManagedDatabaseAdvancedThreatProtectionSettingsOperations operations + :vartype managed_database_advanced_threat_protection_settings: + azure.mgmt.sql.aio.operations.ManagedDatabaseAdvancedThreatProtectionSettingsOperations + :ivar managed_instance_advanced_threat_protection_settings: + ManagedInstanceAdvancedThreatProtectionSettingsOperations operations + :vartype managed_instance_advanced_threat_protection_settings: + azure.mgmt.sql.aio.operations.ManagedInstanceAdvancedThreatProtectionSettingsOperations + :ivar replication_links: ReplicationLinksOperations operations + :vartype replication_links: azure.mgmt.sql.aio.operations.ReplicationLinksOperations + :ivar managed_database_restore_details: ManagedDatabaseRestoreDetailsOperations operations + :vartype managed_database_restore_details: + azure.mgmt.sql.aio.operations.ManagedDatabaseRestoreDetailsOperations + :ivar managed_databases: ManagedDatabasesOperations operations + :vartype managed_databases: azure.mgmt.sql.aio.operations.ManagedDatabasesOperations + :param credential: Credential needed for the client to connect to Azure. Required. :type credential: ~azure.core.credentials_async.AsyncTokenCredential - :param subscription_id: The subscription ID that identifies an Azure subscription. + :param subscription_id: The subscription ID that identifies an Azure subscription. Required. :type subscription_id: str :param base_url: Service URL. Default value is "https://management.azure.com". :type base_url: str @@ -380,7 +519,9 @@ def __init__( base_url: str = "https://management.azure.com", **kwargs: Any ) -> None: - self._config = SqlManagementClientConfiguration(credential=credential, subscription_id=subscription_id, **kwargs) + self._config = SqlManagementClientConfiguration( + 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)} @@ -399,12 +540,8 @@ def __init__( self.geo_backup_policies = GeoBackupPoliciesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.databases = DatabasesOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.elastic_pools = ElasticPoolsOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.databases = DatabasesOperations(self._client, self._config, self._serialize, self._deserialize) + self.elastic_pools = ElasticPoolsOperations(self._client, self._config, self._serialize, self._deserialize) self.server_communication_links = ServerCommunicationLinksOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -417,9 +554,7 @@ def __init__( self.elastic_pool_database_activities = ElasticPoolDatabaseActivitiesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.server_usages = ServerUsagesOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.server_usages = ServerUsagesOperations(self._client, self._config, self._serialize, self._deserialize) self.database_advisors = DatabaseAdvisorsOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -438,9 +573,7 @@ def __init__( self.database_security_alert_policies = DatabaseSecurityAlertPoliciesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.database_tables = DatabaseTablesOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.database_tables = DatabaseTablesOperations(self._client, self._config, self._serialize, self._deserialize) self.database_vulnerability_assessment_rule_baselines = DatabaseVulnerabilityAssessmentRuleBaselinesOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -453,57 +586,35 @@ def __init__( self.data_warehouse_user_activities = DataWarehouseUserActivitiesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.deleted_servers = DeletedServersOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.deleted_servers = DeletedServersOperations(self._client, self._config, self._serialize, self._deserialize) self.elastic_pool_operations = ElasticPoolOperationsOperations( self._client, self._config, self._serialize, self._deserialize ) self.encryption_protectors = EncryptionProtectorsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.failover_groups = FailoverGroupsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.firewall_rules = FirewallRulesOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.failover_groups = FailoverGroupsOperations(self._client, self._config, self._serialize, self._deserialize) + self.firewall_rules = FirewallRulesOperations(self._client, self._config, self._serialize, self._deserialize) self.instance_failover_groups = InstanceFailoverGroupsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.instance_pools = InstancePoolsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.job_agents = JobAgentsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.job_credentials = JobCredentialsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.job_executions = JobExecutionsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.jobs = JobsOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.instance_pools = InstancePoolsOperations(self._client, self._config, self._serialize, self._deserialize) + self.job_agents = JobAgentsOperations(self._client, self._config, self._serialize, self._deserialize) + self.job_credentials = JobCredentialsOperations(self._client, self._config, self._serialize, self._deserialize) + self.job_executions = JobExecutionsOperations(self._client, self._config, self._serialize, self._deserialize) + self.jobs = JobsOperations(self._client, self._config, self._serialize, self._deserialize) self.job_step_executions = JobStepExecutionsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.job_steps = JobStepsOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.job_steps = JobStepsOperations(self._client, self._config, self._serialize, self._deserialize) self.job_target_executions = JobTargetExecutionsOperations( self._client, self._config, self._serialize, self._deserialize ) self.job_target_groups = JobTargetGroupsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.job_versions = JobVersionsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.capabilities = CapabilitiesOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.job_versions = JobVersionsOperations(self._client, self._config, self._serialize, self._deserialize) + self.capabilities = CapabilitiesOperations(self._client, self._config, self._serialize, self._deserialize) self.long_term_retention_policies = LongTermRetentionPoliciesOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -522,12 +633,6 @@ def __init__( self.managed_database_queries = ManagedDatabaseQueriesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.managed_database_restore_details = ManagedDatabaseRestoreDetailsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.managed_databases = ManagedDatabasesOperations( - self._client, self._config, self._serialize, self._deserialize - ) self.managed_database_schemas = ManagedDatabaseSchemasOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -543,8 +648,10 @@ def __init__( self.managed_database_transparent_data_encryption = ManagedDatabaseTransparentDataEncryptionOperations( self._client, self._config, self._serialize, self._deserialize ) - self.managed_database_vulnerability_assessment_rule_baselines = ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations( - self._client, self._config, self._serialize, self._deserialize + self.managed_database_vulnerability_assessment_rule_baselines = ( + ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations( + self._client, self._config, self._serialize, self._deserialize + ) ) self.managed_database_vulnerability_assessments = ManagedDatabaseVulnerabilityAssessmentsOperations( self._client, self._config, self._serialize, self._deserialize @@ -582,15 +689,15 @@ def __init__( self.managed_instance_vulnerability_assessments = ManagedInstanceVulnerabilityAssessmentsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.managed_restorable_dropped_database_backup_short_term_retention_policies = ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations( - self._client, self._config, self._serialize, self._deserialize + self.managed_restorable_dropped_database_backup_short_term_retention_policies = ( + ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations( + self._client, self._config, self._serialize, self._deserialize + ) ) self.managed_server_security_alert_policies = ManagedServerSecurityAlertPoliciesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.operations = Operations( - self._client, self._config, self._serialize, self._deserialize - ) + self.operations = Operations(self._client, self._config, self._serialize, self._deserialize) self.private_endpoint_connections = PrivateEndpointConnectionsOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -600,12 +707,8 @@ def __init__( self.recoverable_managed_databases = RecoverableManagedDatabasesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.restore_points = RestorePointsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.server_advisors = ServerAdvisorsOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.restore_points = RestorePointsOperations(self._client, self._config, self._serialize, self._deserialize) + self.server_advisors = ServerAdvisorsOperations(self._client, self._config, self._serialize, self._deserialize) self.server_automatic_tuning = ServerAutomaticTuningOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -621,9 +724,7 @@ def __init__( self.server_dns_aliases = ServerDnsAliasesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.server_keys = ServerKeysOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.server_keys = ServerKeysOperations(self._client, self._config, self._serialize, self._deserialize) self.server_operations = ServerOperationsOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -636,27 +737,17 @@ def __init__( self.server_vulnerability_assessments = ServerVulnerabilityAssessmentsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.sql_agent = SqlAgentOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.sql_agent = SqlAgentOperations(self._client, self._config, self._serialize, self._deserialize) self.subscription_usages = SubscriptionUsagesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.sync_agents = SyncAgentsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.sync_groups = SyncGroupsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.sync_members = SyncMembersOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.sync_agents = SyncAgentsOperations(self._client, self._config, self._serialize, self._deserialize) + self.sync_groups = SyncGroupsOperations(self._client, self._config, self._serialize, self._deserialize) + self.sync_members = SyncMembersOperations(self._client, self._config, self._serialize, self._deserialize) self.tde_certificates = TdeCertificatesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.time_zones = TimeZonesOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.time_zones = TimeZonesOperations(self._client, self._config, self._serialize, self._deserialize) self.virtual_clusters = VirtualClustersOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -666,9 +757,7 @@ def __init__( self.workload_classifiers = WorkloadClassifiersOperations( self._client, self._config, self._serialize, self._deserialize ) - self.workload_groups = WorkloadGroupsOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.workload_groups = WorkloadGroupsOperations(self._client, self._config, self._serialize, self._deserialize) self.transparent_data_encryptions = TransparentDataEncryptionsOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -681,21 +770,15 @@ def __init__( self.database_operations = DatabaseOperationsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.database_usages = DatabaseUsagesOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.database_usages = DatabaseUsagesOperations(self._client, self._config, self._serialize, self._deserialize) self.ledger_digest_uploads = LedgerDigestUploadsOperations( self._client, self._config, self._serialize, self._deserialize ) self.outbound_firewall_rules = OutboundFirewallRulesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.servers = ServersOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.usages = UsagesOperations( - self._client, self._config, self._serialize, self._deserialize - ) + self.servers = ServersOperations(self._client, self._config, self._serialize, self._deserialize) + self.usages = UsagesOperations(self._client, self._config, self._serialize, self._deserialize) self.long_term_retention_backups = LongTermRetentionBackupsOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -726,9 +809,6 @@ def __init__( self.endpoint_certificates = EndpointCertificatesOperations( self._client, self._config, self._serialize, self._deserialize ) - self.replication_links = ReplicationLinksOperations( - self._client, self._config, self._serialize, self._deserialize - ) self.managed_database_sensitivity_labels = ManagedDatabaseSensitivityLabelsOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -762,13 +842,30 @@ def __init__( self.managed_server_dns_aliases = ManagedServerDnsAliasesOperations( self._client, self._config, self._serialize, self._deserialize ) + self.managed_instance_dtcs = ManagedInstanceDtcsOperations( + self._client, self._config, self._serialize, self._deserialize + ) + self.managed_database_advanced_threat_protection_settings = ( + ManagedDatabaseAdvancedThreatProtectionSettingsOperations( + self._client, self._config, self._serialize, self._deserialize + ) + ) + self.managed_instance_advanced_threat_protection_settings = ( + ManagedInstanceAdvancedThreatProtectionSettingsOperations( + self._client, self._config, self._serialize, self._deserialize + ) + ) + self.replication_links = ReplicationLinksOperations( + self._client, self._config, self._serialize, self._deserialize + ) + self.managed_database_restore_details = ManagedDatabaseRestoreDetailsOperations( + self._client, self._config, self._serialize, self._deserialize + ) + self.managed_databases = ManagedDatabasesOperations( + self._client, self._config, self._serialize, self._deserialize + ) - - def _send_request( - self, - request: HttpRequest, - **kwargs: Any - ) -> Awaitable[AsyncHttpResponse]: + def _send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]: """Runs the network request through the client's chained policies. >>> from azure.core.rest import HttpRequest @@ -777,7 +874,7 @@ def _send_request( >>> response = await client._send_request(request) - For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart + For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request :param request: The network request you want to make. Required. :type request: ~azure.core.rest.HttpRequest diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/__init__.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/__init__.py index 3848df9ec3ed4..1c28b37b61019 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/__init__.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/__init__.py @@ -24,7 +24,9 @@ from ._database_schemas_operations import DatabaseSchemasOperations from ._database_security_alert_policies_operations import DatabaseSecurityAlertPoliciesOperations from ._database_tables_operations import DatabaseTablesOperations -from ._database_vulnerability_assessment_rule_baselines_operations import DatabaseVulnerabilityAssessmentRuleBaselinesOperations +from ._database_vulnerability_assessment_rule_baselines_operations import ( + DatabaseVulnerabilityAssessmentRuleBaselinesOperations, +) from ._database_vulnerability_assessments_operations import DatabaseVulnerabilityAssessmentsOperations from ._database_vulnerability_assessment_scans_operations import DatabaseVulnerabilityAssessmentScansOperations from ._data_warehouse_user_activities_operations import DataWarehouseUserActivitiesOperations @@ -51,27 +53,37 @@ from ._managed_backup_short_term_retention_policies_operations import ManagedBackupShortTermRetentionPoliciesOperations from ._managed_database_columns_operations import ManagedDatabaseColumnsOperations from ._managed_database_queries_operations import ManagedDatabaseQueriesOperations -from ._managed_database_restore_details_operations import ManagedDatabaseRestoreDetailsOperations -from ._managed_databases_operations import ManagedDatabasesOperations from ._managed_database_schemas_operations import ManagedDatabaseSchemasOperations from ._managed_database_security_alert_policies_operations import ManagedDatabaseSecurityAlertPoliciesOperations from ._managed_database_security_events_operations import ManagedDatabaseSecurityEventsOperations from ._managed_database_tables_operations import ManagedDatabaseTablesOperations from ._managed_database_transparent_data_encryption_operations import ManagedDatabaseTransparentDataEncryptionOperations -from ._managed_database_vulnerability_assessment_rule_baselines_operations import ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations +from ._managed_database_vulnerability_assessment_rule_baselines_operations import ( + ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations, +) from ._managed_database_vulnerability_assessments_operations import ManagedDatabaseVulnerabilityAssessmentsOperations -from ._managed_database_vulnerability_assessment_scans_operations import ManagedDatabaseVulnerabilityAssessmentScansOperations +from ._managed_database_vulnerability_assessment_scans_operations import ( + ManagedDatabaseVulnerabilityAssessmentScansOperations, +) from ._managed_instance_administrators_operations import ManagedInstanceAdministratorsOperations -from ._managed_instance_azure_ad_only_authentications_operations import ManagedInstanceAzureADOnlyAuthenticationsOperations +from ._managed_instance_azure_ad_only_authentications_operations import ( + ManagedInstanceAzureADOnlyAuthenticationsOperations, +) from ._managed_instance_encryption_protectors_operations import ManagedInstanceEncryptionProtectorsOperations from ._managed_instance_keys_operations import ManagedInstanceKeysOperations -from ._managed_instance_long_term_retention_policies_operations import ManagedInstanceLongTermRetentionPoliciesOperations +from ._managed_instance_long_term_retention_policies_operations import ( + ManagedInstanceLongTermRetentionPoliciesOperations, +) from ._managed_instance_operations_operations import ManagedInstanceOperationsOperations -from ._managed_instance_private_endpoint_connections_operations import ManagedInstancePrivateEndpointConnectionsOperations +from ._managed_instance_private_endpoint_connections_operations import ( + ManagedInstancePrivateEndpointConnectionsOperations, +) from ._managed_instance_private_link_resources_operations import ManagedInstancePrivateLinkResourcesOperations from ._managed_instance_tde_certificates_operations import ManagedInstanceTdeCertificatesOperations from ._managed_instance_vulnerability_assessments_operations import ManagedInstanceVulnerabilityAssessmentsOperations -from ._managed_restorable_dropped_database_backup_short_term_retention_policies_operations import ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations +from ._managed_restorable_dropped_database_backup_short_term_retention_policies_operations import ( + ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations, +) from ._managed_server_security_alert_policies_operations import ManagedServerSecurityAlertPoliciesOperations from ._operations import Operations from ._private_endpoint_connections_operations import PrivateEndpointConnectionsOperations @@ -119,9 +131,10 @@ from ._server_trust_certificates_operations import ServerTrustCertificatesOperations from ._ipv6_firewall_rules_operations import IPv6FirewallRulesOperations from ._endpoint_certificates_operations import EndpointCertificatesOperations -from ._replication_links_operations import ReplicationLinksOperations from ._managed_database_sensitivity_labels_operations import ManagedDatabaseSensitivityLabelsOperations -from ._managed_database_recommended_sensitivity_labels_operations import ManagedDatabaseRecommendedSensitivityLabelsOperations +from ._managed_database_recommended_sensitivity_labels_operations import ( + ManagedDatabaseRecommendedSensitivityLabelsOperations, +) from ._sensitivity_labels_operations import SensitivityLabelsOperations from ._recommended_sensitivity_labels_operations import RecommendedSensitivityLabelsOperations from ._server_blob_auditing_policies_operations import ServerBlobAuditingPoliciesOperations @@ -131,136 +144,150 @@ from ._database_advanced_threat_protection_settings_operations import DatabaseAdvancedThreatProtectionSettingsOperations from ._server_advanced_threat_protection_settings_operations import ServerAdvancedThreatProtectionSettingsOperations from ._managed_server_dns_aliases_operations import ManagedServerDnsAliasesOperations +from ._managed_instance_dtcs_operations import ManagedInstanceDtcsOperations +from ._managed_database_advanced_threat_protection_settings_operations import ( + ManagedDatabaseAdvancedThreatProtectionSettingsOperations, +) +from ._managed_instance_advanced_threat_protection_settings_operations import ( + ManagedInstanceAdvancedThreatProtectionSettingsOperations, +) +from ._replication_links_operations import ReplicationLinksOperations +from ._managed_database_restore_details_operations import ManagedDatabaseRestoreDetailsOperations +from ._managed_databases_operations import ManagedDatabasesOperations from ._patch import __all__ as _patch_all from ._patch import * # type: ignore # pylint: disable=unused-wildcard-import from ._patch import patch_sdk as _patch_sdk + __all__ = [ - 'RecoverableDatabasesOperations', - 'DataMaskingPoliciesOperations', - 'DataMaskingRulesOperations', - 'GeoBackupPoliciesOperations', - 'DatabasesOperations', - 'ElasticPoolsOperations', - 'ServerCommunicationLinksOperations', - 'ServiceObjectivesOperations', - 'ElasticPoolActivitiesOperations', - 'ElasticPoolDatabaseActivitiesOperations', - 'ServerUsagesOperations', - 'DatabaseAdvisorsOperations', - 'DatabaseAutomaticTuningOperations', - 'DatabaseColumnsOperations', - 'DatabaseRecommendedActionsOperations', - 'DatabaseSchemasOperations', - 'DatabaseSecurityAlertPoliciesOperations', - 'DatabaseTablesOperations', - 'DatabaseVulnerabilityAssessmentRuleBaselinesOperations', - 'DatabaseVulnerabilityAssessmentsOperations', - 'DatabaseVulnerabilityAssessmentScansOperations', - 'DataWarehouseUserActivitiesOperations', - 'DeletedServersOperations', - 'ElasticPoolOperationsOperations', - 'EncryptionProtectorsOperations', - 'FailoverGroupsOperations', - 'FirewallRulesOperations', - 'InstanceFailoverGroupsOperations', - 'InstancePoolsOperations', - 'JobAgentsOperations', - 'JobCredentialsOperations', - 'JobExecutionsOperations', - 'JobsOperations', - 'JobStepExecutionsOperations', - 'JobStepsOperations', - 'JobTargetExecutionsOperations', - 'JobTargetGroupsOperations', - 'JobVersionsOperations', - 'CapabilitiesOperations', - 'LongTermRetentionPoliciesOperations', - 'MaintenanceWindowOptionsOperations', - 'MaintenanceWindowsOperations', - 'ManagedBackupShortTermRetentionPoliciesOperations', - 'ManagedDatabaseColumnsOperations', - 'ManagedDatabaseQueriesOperations', - 'ManagedDatabaseRestoreDetailsOperations', - 'ManagedDatabasesOperations', - 'ManagedDatabaseSchemasOperations', - 'ManagedDatabaseSecurityAlertPoliciesOperations', - 'ManagedDatabaseSecurityEventsOperations', - 'ManagedDatabaseTablesOperations', - 'ManagedDatabaseTransparentDataEncryptionOperations', - 'ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations', - 'ManagedDatabaseVulnerabilityAssessmentsOperations', - 'ManagedDatabaseVulnerabilityAssessmentScansOperations', - 'ManagedInstanceAdministratorsOperations', - 'ManagedInstanceAzureADOnlyAuthenticationsOperations', - 'ManagedInstanceEncryptionProtectorsOperations', - 'ManagedInstanceKeysOperations', - 'ManagedInstanceLongTermRetentionPoliciesOperations', - 'ManagedInstanceOperationsOperations', - 'ManagedInstancePrivateEndpointConnectionsOperations', - 'ManagedInstancePrivateLinkResourcesOperations', - 'ManagedInstanceTdeCertificatesOperations', - 'ManagedInstanceVulnerabilityAssessmentsOperations', - 'ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations', - 'ManagedServerSecurityAlertPoliciesOperations', - 'Operations', - 'PrivateEndpointConnectionsOperations', - 'PrivateLinkResourcesOperations', - 'RecoverableManagedDatabasesOperations', - 'RestorePointsOperations', - 'ServerAdvisorsOperations', - 'ServerAutomaticTuningOperations', - 'ServerAzureADAdministratorsOperations', - 'ServerAzureADOnlyAuthenticationsOperations', - 'ServerDevOpsAuditSettingsOperations', - 'ServerDnsAliasesOperations', - 'ServerKeysOperations', - 'ServerOperationsOperations', - 'ServerSecurityAlertPoliciesOperations', - 'ServerTrustGroupsOperations', - 'ServerVulnerabilityAssessmentsOperations', - 'SqlAgentOperations', - 'SubscriptionUsagesOperations', - 'SyncAgentsOperations', - 'SyncGroupsOperations', - 'SyncMembersOperations', - 'TdeCertificatesOperations', - 'TimeZonesOperations', - 'VirtualClustersOperations', - 'VirtualNetworkRulesOperations', - 'WorkloadClassifiersOperations', - 'WorkloadGroupsOperations', - 'TransparentDataEncryptionsOperations', - 'BackupShortTermRetentionPoliciesOperations', - 'DatabaseExtensionsOperations', - 'DatabaseOperationsOperations', - 'DatabaseUsagesOperations', - 'LedgerDigestUploadsOperations', - 'OutboundFirewallRulesOperations', - 'ServersOperations', - 'UsagesOperations', - 'LongTermRetentionBackupsOperations', - 'LongTermRetentionManagedInstanceBackupsOperations', - 'ManagedInstancesOperations', - 'RestorableDroppedDatabasesOperations', - 'RestorableDroppedManagedDatabasesOperations', - 'ServerConnectionPoliciesOperations', - 'DistributedAvailabilityGroupsOperations', - 'ServerTrustCertificatesOperations', - 'IPv6FirewallRulesOperations', - 'EndpointCertificatesOperations', - 'ReplicationLinksOperations', - 'ManagedDatabaseSensitivityLabelsOperations', - 'ManagedDatabaseRecommendedSensitivityLabelsOperations', - 'SensitivityLabelsOperations', - 'RecommendedSensitivityLabelsOperations', - 'ServerBlobAuditingPoliciesOperations', - 'DatabaseBlobAuditingPoliciesOperations', - 'ExtendedDatabaseBlobAuditingPoliciesOperations', - 'ExtendedServerBlobAuditingPoliciesOperations', - 'DatabaseAdvancedThreatProtectionSettingsOperations', - 'ServerAdvancedThreatProtectionSettingsOperations', - 'ManagedServerDnsAliasesOperations', + "RecoverableDatabasesOperations", + "DataMaskingPoliciesOperations", + "DataMaskingRulesOperations", + "GeoBackupPoliciesOperations", + "DatabasesOperations", + "ElasticPoolsOperations", + "ServerCommunicationLinksOperations", + "ServiceObjectivesOperations", + "ElasticPoolActivitiesOperations", + "ElasticPoolDatabaseActivitiesOperations", + "ServerUsagesOperations", + "DatabaseAdvisorsOperations", + "DatabaseAutomaticTuningOperations", + "DatabaseColumnsOperations", + "DatabaseRecommendedActionsOperations", + "DatabaseSchemasOperations", + "DatabaseSecurityAlertPoliciesOperations", + "DatabaseTablesOperations", + "DatabaseVulnerabilityAssessmentRuleBaselinesOperations", + "DatabaseVulnerabilityAssessmentsOperations", + "DatabaseVulnerabilityAssessmentScansOperations", + "DataWarehouseUserActivitiesOperations", + "DeletedServersOperations", + "ElasticPoolOperationsOperations", + "EncryptionProtectorsOperations", + "FailoverGroupsOperations", + "FirewallRulesOperations", + "InstanceFailoverGroupsOperations", + "InstancePoolsOperations", + "JobAgentsOperations", + "JobCredentialsOperations", + "JobExecutionsOperations", + "JobsOperations", + "JobStepExecutionsOperations", + "JobStepsOperations", + "JobTargetExecutionsOperations", + "JobTargetGroupsOperations", + "JobVersionsOperations", + "CapabilitiesOperations", + "LongTermRetentionPoliciesOperations", + "MaintenanceWindowOptionsOperations", + "MaintenanceWindowsOperations", + "ManagedBackupShortTermRetentionPoliciesOperations", + "ManagedDatabaseColumnsOperations", + "ManagedDatabaseQueriesOperations", + "ManagedDatabaseSchemasOperations", + "ManagedDatabaseSecurityAlertPoliciesOperations", + "ManagedDatabaseSecurityEventsOperations", + "ManagedDatabaseTablesOperations", + "ManagedDatabaseTransparentDataEncryptionOperations", + "ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations", + "ManagedDatabaseVulnerabilityAssessmentsOperations", + "ManagedDatabaseVulnerabilityAssessmentScansOperations", + "ManagedInstanceAdministratorsOperations", + "ManagedInstanceAzureADOnlyAuthenticationsOperations", + "ManagedInstanceEncryptionProtectorsOperations", + "ManagedInstanceKeysOperations", + "ManagedInstanceLongTermRetentionPoliciesOperations", + "ManagedInstanceOperationsOperations", + "ManagedInstancePrivateEndpointConnectionsOperations", + "ManagedInstancePrivateLinkResourcesOperations", + "ManagedInstanceTdeCertificatesOperations", + "ManagedInstanceVulnerabilityAssessmentsOperations", + "ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations", + "ManagedServerSecurityAlertPoliciesOperations", + "Operations", + "PrivateEndpointConnectionsOperations", + "PrivateLinkResourcesOperations", + "RecoverableManagedDatabasesOperations", + "RestorePointsOperations", + "ServerAdvisorsOperations", + "ServerAutomaticTuningOperations", + "ServerAzureADAdministratorsOperations", + "ServerAzureADOnlyAuthenticationsOperations", + "ServerDevOpsAuditSettingsOperations", + "ServerDnsAliasesOperations", + "ServerKeysOperations", + "ServerOperationsOperations", + "ServerSecurityAlertPoliciesOperations", + "ServerTrustGroupsOperations", + "ServerVulnerabilityAssessmentsOperations", + "SqlAgentOperations", + "SubscriptionUsagesOperations", + "SyncAgentsOperations", + "SyncGroupsOperations", + "SyncMembersOperations", + "TdeCertificatesOperations", + "TimeZonesOperations", + "VirtualClustersOperations", + "VirtualNetworkRulesOperations", + "WorkloadClassifiersOperations", + "WorkloadGroupsOperations", + "TransparentDataEncryptionsOperations", + "BackupShortTermRetentionPoliciesOperations", + "DatabaseExtensionsOperations", + "DatabaseOperationsOperations", + "DatabaseUsagesOperations", + "LedgerDigestUploadsOperations", + "OutboundFirewallRulesOperations", + "ServersOperations", + "UsagesOperations", + "LongTermRetentionBackupsOperations", + "LongTermRetentionManagedInstanceBackupsOperations", + "ManagedInstancesOperations", + "RestorableDroppedDatabasesOperations", + "RestorableDroppedManagedDatabasesOperations", + "ServerConnectionPoliciesOperations", + "DistributedAvailabilityGroupsOperations", + "ServerTrustCertificatesOperations", + "IPv6FirewallRulesOperations", + "EndpointCertificatesOperations", + "ManagedDatabaseSensitivityLabelsOperations", + "ManagedDatabaseRecommendedSensitivityLabelsOperations", + "SensitivityLabelsOperations", + "RecommendedSensitivityLabelsOperations", + "ServerBlobAuditingPoliciesOperations", + "DatabaseBlobAuditingPoliciesOperations", + "ExtendedDatabaseBlobAuditingPoliciesOperations", + "ExtendedServerBlobAuditingPoliciesOperations", + "DatabaseAdvancedThreatProtectionSettingsOperations", + "ServerAdvancedThreatProtectionSettingsOperations", + "ManagedServerDnsAliasesOperations", + "ManagedInstanceDtcsOperations", + "ManagedDatabaseAdvancedThreatProtectionSettingsOperations", + "ManagedInstanceAdvancedThreatProtectionSettingsOperations", + "ReplicationLinksOperations", + "ManagedDatabaseRestoreDetailsOperations", + "ManagedDatabasesOperations", ] __all__.extend([p for p in _patch_all if p not in __all__]) -_patch_sdk() \ No newline at end of file +_patch_sdk() diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_backup_short_term_retention_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_backup_short_term_retention_policies_operations.py index f151fc29a61cd..b757e56048831 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_backup_short_term_retention_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_backup_short_term_retention_policies_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._backup_short_term_retention_policies_operations import build_create_or_update_request_initial, build_get_request, build_list_by_database_request, build_update_request_initial -T = TypeVar('T') +from ...operations._backup_short_term_retention_policies_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_database_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class BackupShortTermRetentionPoliciesOperations: """ .. warning:: @@ -45,7 +58,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -58,34 +70,28 @@ async def get( """Gets a database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be "default". + :param policy_name: The policy name. Should always be "default". "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ShortTermRetentionPolicyName - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: BackupShortTermRetentionPolicy, or the result of cls(response) + :return: BackupShortTermRetentionPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.BackupShortTermRetentionPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.BackupShortTermRetentionPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.BackupShortTermRetentionPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -93,7 +99,7 @@ async def get( policy_name=policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -101,25 +107,23 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('BackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("BackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore async def _create_or_update_initial( self, @@ -127,24 +131,28 @@ async def _create_or_update_initial( server_name: str, database_name: str, policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], - parameters: _models.BackupShortTermRetentionPolicy, + parameters: Union[_models.BackupShortTermRetentionPolicy, IO], **kwargs: Any ) -> Optional[_models.BackupShortTermRetentionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.BackupShortTermRetentionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.BackupShortTermRetentionPolicy]] - _json = self._serialize.body(parameters, 'BackupShortTermRetentionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "BackupShortTermRetentionPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -153,7 +161,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -161,10 +170,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -173,17 +181,16 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('BackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("BackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, @@ -191,24 +198,26 @@ async def begin_create_or_update( database_name: str, policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], parameters: _models.BackupShortTermRetentionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.BackupShortTermRetentionPolicy]: """Updates a database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be "default". + :param policy_name: The policy name. Should always be "default". "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ShortTermRetentionPolicyName - :param parameters: The short term retention policy info. + :param parameters: The short term retention policy info. Required. :type parameters: ~azure.mgmt.sql.models.BackupShortTermRetentionPolicy - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -221,20 +230,102 @@ async def begin_create_or_update( the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.BackupShortTermRetentionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.BackupShortTermRetentionPolicy]: + """Updates a database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Required. + :type parameters: IO + :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 BackupShortTermRetentionPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.BackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], + parameters: Union[_models.BackupShortTermRetentionPolicy, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.BackupShortTermRetentionPolicy]: + """Updates a database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.BackupShortTermRetentionPolicy 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. + :return: An instance of AsyncLROPoller that returns either BackupShortTermRetentionPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.BackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.BackupShortTermRetentionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.BackupShortTermRetentionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -244,39 +335,35 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('BackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("BackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore async def _update_initial( self, @@ -284,24 +371,28 @@ async def _update_initial( server_name: str, database_name: str, policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], - parameters: _models.BackupShortTermRetentionPolicy, + parameters: Union[_models.BackupShortTermRetentionPolicy, IO], **kwargs: Any ) -> Optional[_models.BackupShortTermRetentionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.BackupShortTermRetentionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.BackupShortTermRetentionPolicy]] - _json = self._serialize.body(parameters, 'BackupShortTermRetentionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "BackupShortTermRetentionPolicy") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -310,7 +401,8 @@ async def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -318,10 +410,9 @@ async def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -330,17 +421,16 @@ async def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('BackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("BackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - @distributed_trace_async + @overload async def begin_update( self, resource_group_name: str, @@ -348,24 +438,69 @@ async def begin_update( database_name: str, policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], parameters: _models.BackupShortTermRetentionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.BackupShortTermRetentionPolicy]: """Updates a database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be "default". + :param policy_name: The policy name. Should always be "default". "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ShortTermRetentionPolicyName - :param parameters: The short term retention policy info. + :param parameters: The short term retention policy info. Required. :type parameters: ~azure.mgmt.sql.models.BackupShortTermRetentionPolicy - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 BackupShortTermRetentionPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.BackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.BackupShortTermRetentionPolicy]: + """Updates a database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Required. + :type parameters: IO + :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 @@ -378,20 +513,59 @@ async def begin_update( the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.BackupShortTermRetentionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], + parameters: Union[_models.BackupShortTermRetentionPolicy, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.BackupShortTermRetentionPolicy]: + """Updates a database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.BackupShortTermRetentionPolicy 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. + :return: An instance of AsyncLROPoller that returns either BackupShortTermRetentionPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.BackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.BackupShortTermRetentionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.BackupShortTermRetentionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -401,87 +575,75 @@ async def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('BackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("BackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.BackupShortTermRetentionPolicyListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.BackupShortTermRetentionPolicy"]: """Gets a database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either BackupShortTermRetentionPolicyListResult or the - result of cls(response) + :return: An iterator like instance of either BackupShortTermRetentionPolicy or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.BackupShortTermRetentionPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.BackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.BackupShortTermRetentionPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.BackupShortTermRetentionPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -489,17 +651,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -515,10 +667,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -528,8 +678,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_capabilities_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_capabilities_operations.py index f72e7162d8458..ae5da45406d20 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_capabilities_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_capabilities_operations.py @@ -8,7 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Optional, TypeVar, Union -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -19,9 +25,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._capabilities_operations import build_list_by_location_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class CapabilitiesOperations: """ .. warning:: @@ -41,47 +49,39 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def list_by_location( - self, - location_name: str, - include: Optional[Union[str, "_models.CapabilityGroup"]] = None, - **kwargs: Any + self, location_name: str, include: Optional[Union[str, "_models.CapabilityGroup"]] = None, **kwargs: Any ) -> _models.LocationCapabilities: """Gets the subscription capabilities available for the specified location. - :param location_name: The location name whose capabilities are retrieved. + :param location_name: The location name whose capabilities are retrieved. Required. :type location_name: str - :param include: If specified, restricts the response to only include the selected item. Default - value is None. + :param include: If specified, restricts the response to only include the selected item. Known + values are: "supportedEditions", "supportedElasticPoolEditions", + "supportedManagedInstanceVersions", "supportedInstancePoolEditions", and + "supportedManagedInstanceEditions". Default value is None. :type include: str or ~azure.mgmt.sql.models.CapabilityGroup - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: LocationCapabilities, or the result of cls(response) + :return: LocationCapabilities or the result of cls(response) :rtype: ~azure.mgmt.sql.models.LocationCapabilities - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LocationCapabilities] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LocationCapabilities] - request = build_list_by_location_request( location_name=location_name, subscription_id=self._config.subscription_id, - api_version=api_version, include=include, - template_url=self.list_by_location.metadata['url'], + api_version=api_version, + template_url=self.list_by_location.metadata["url"], headers=_headers, params=_params, ) @@ -89,22 +89,20 @@ async def list_by_location( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('LocationCapabilities', pipeline_response) + deserialized = self._deserialize("LocationCapabilities", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/capabilities"} # type: ignore - + list_by_location.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/capabilities"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_data_masking_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_data_masking_policies_operations.py index b30ecc98856b2..a0a23d31f499d 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_data_masking_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_data_masking_policies_operations.py @@ -6,9 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -19,9 +25,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._data_masking_policies_operations import build_create_or_update_request, build_get_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DataMaskingPoliciesOperations: """ .. warning:: @@ -41,64 +49,139 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.DataMaskingPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DataMaskingPolicy: """Creates or updates a database data masking policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: Parameters for creating or updating a data masking policy. + :param parameters: Parameters for creating or updating a data masking policy. Required. :type parameters: ~azure.mgmt.sql.models.DataMaskingPolicy - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str :keyword data_masking_policy_name: The name of the database for which the data masking rule applies. Default value is "Default". Note that overriding this default value may result in unsupported behavior. :paramtype data_masking_policy_name: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DataMaskingPolicy, or the result of cls(response) + :return: DataMaskingPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DataMaskingPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DataMaskingPolicy: + """Creates or updates a database data masking policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters for creating or updating a data masking policy. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword data_masking_policy_name: The name of the database for which the data masking rule + applies. Default value is "Default". Note that overriding this default value may result in + unsupported behavior. + :paramtype data_masking_policy_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: DataMaskingPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DataMaskingPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.DataMaskingPolicy, IO], + **kwargs: Any + ) -> _models.DataMaskingPolicy: + """Creates or updates a database data masking policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters for creating or updating a data masking policy. Is either a model + type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.DataMaskingPolicy or IO + :keyword data_masking_policy_name: The name of the database for which the data masking rule + applies. Default value is "Default". Note that overriding this default value may result in + unsupported behavior. + :paramtype data_masking_policy_name: str + :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 + :return: DataMaskingPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DataMaskingPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - data_masking_policy_name = kwargs.pop('data_masking_policy_name', "Default") # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DataMaskingPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + data_masking_policy_name = kwargs.pop("data_masking_policy_name", "Default") # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DataMaskingPolicy] - _json = self._serialize.body(parameters, 'DataMaskingPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DataMaskingPolicy") request = build_create_or_update_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, + subscription_id=self._config.subscription_id, api_version=api_version, data_masking_policy_name=data_masking_policy_name, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -106,76 +189,64 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DataMaskingPolicy', pipeline_response) + deserialized = self._deserialize("DataMaskingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> _models.DataMaskingPolicy: """Gets a database data masking policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword data_masking_policy_name: The name of the database for which the data masking rule applies. Default value is "Default". Note that overriding this default value may result in unsupported behavior. :paramtype data_masking_policy_name: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DataMaskingPolicy, or the result of cls(response) + :return: DataMaskingPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DataMaskingPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - data_masking_policy_name = kwargs.pop('data_masking_policy_name', "Default") # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DataMaskingPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + data_masking_policy_name = kwargs.pop("data_masking_policy_name", "Default") # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DataMaskingPolicy] - request = build_get_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, + subscription_id=self._config.subscription_id, api_version=api_version, data_masking_policy_name=data_masking_policy_name, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -183,22 +254,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DataMaskingPolicy', pipeline_response) + deserialized = self._deserialize("DataMaskingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_data_masking_rules_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_data_masking_rules_operations.py index c10e57d605307..43d8f93e82107 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_data_masking_rules_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_data_masking_rules_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._data_masking_rules_operations import build_create_or_update_request, build_list_by_database_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DataMaskingRulesOperations: """ .. warning:: @@ -43,8 +51,7 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, @@ -52,59 +59,143 @@ async def create_or_update( database_name: str, data_masking_rule_name: str, parameters: _models.DataMaskingRule, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DataMaskingRule: """Creates or updates a database data masking rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param data_masking_rule_name: The name of the data masking rule. + :param data_masking_rule_name: The name of the data masking rule. Required. :type data_masking_rule_name: str :param parameters: The required parameters for creating or updating a data masking rule. + Required. :type parameters: ~azure.mgmt.sql.models.DataMaskingRule - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword data_masking_policy_name: The name of the database for which the data masking rule + applies. Default value is "Default". Note that overriding this default value may result in + unsupported behavior. + :paramtype data_masking_policy_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: DataMaskingRule or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DataMaskingRule + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + data_masking_rule_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DataMaskingRule: + """Creates or updates a database data masking rule. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param data_masking_rule_name: The name of the data masking rule. Required. + :type data_masking_rule_name: str + :param parameters: The required parameters for creating or updating a data masking rule. + Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword data_masking_policy_name: The name of the database for which the data masking rule + applies. Default value is "Default". Note that overriding this default value may result in + unsupported behavior. + :paramtype data_masking_policy_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: DataMaskingRule or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DataMaskingRule + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + data_masking_rule_name: str, + parameters: Union[_models.DataMaskingRule, IO], + **kwargs: Any + ) -> _models.DataMaskingRule: + """Creates or updates a database data masking rule. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param data_masking_rule_name: The name of the data masking rule. Required. + :type data_masking_rule_name: str + :param parameters: The required parameters for creating or updating a data masking rule. Is + either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.DataMaskingRule or IO :keyword data_masking_policy_name: The name of the database for which the data masking rule applies. Default value is "Default". Note that overriding this default value may result in unsupported behavior. :paramtype data_masking_policy_name: str + :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 - :return: DataMaskingRule, or the result of cls(response) + :return: DataMaskingRule or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DataMaskingRule - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - data_masking_policy_name = kwargs.pop('data_masking_policy_name', "Default") # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DataMaskingRule] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + data_masking_policy_name = kwargs.pop("data_masking_policy_name", "Default") # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DataMaskingRule] - _json = self._serialize.body(parameters, 'DataMaskingRule') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DataMaskingRule") request = build_create_or_update_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, data_masking_rule_name=data_masking_rule_name, + subscription_id=self._config.subscription_id, api_version=api_version, data_masking_policy_name=data_masking_policy_name, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -112,10 +203,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -123,72 +213,61 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('DataMaskingRule', pipeline_response) + deserialized = self._deserialize("DataMaskingRule", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DataMaskingRule', pipeline_response) + deserialized = self._deserialize("DataMaskingRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}/rules/{dataMaskingRuleName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}/rules/{dataMaskingRuleName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.DataMaskingRuleListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.DataMaskingRule"]: """Gets a list of database data masking rules. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword data_masking_policy_name: The name of the database for which the data masking rule applies. Default value is "Default". Note that overriding this default value may result in unsupported behavior. :paramtype data_masking_policy_name: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DataMaskingRuleListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DataMaskingRuleListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DataMaskingRule or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DataMaskingRule] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - data_masking_policy_name = kwargs.pop('data_masking_policy_name', "Default") # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DataMaskingRuleListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + data_masking_policy_name = kwargs.pop("data_masking_policy_name", "Default") # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DataMaskingRuleListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, + subscription_id=self._config.subscription_id, api_version=api_version, data_masking_policy_name=data_masking_policy_name, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -196,18 +275,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - api_version=api_version, - data_masking_policy_name=data_masking_policy_name, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -223,10 +291,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -236,8 +302,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}/rules"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}/rules"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_data_warehouse_user_activities_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_data_warehouse_user_activities_operations.py index 5f2edbea2ee8f..0641506814e30 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_data_warehouse_user_activities_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_data_warehouse_user_activities_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._data_warehouse_user_activities_operations import build_get_request, build_list_by_database_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DataWarehouseUserActivitiesOperations: """ .. warning:: @@ -43,7 +51,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -56,35 +63,30 @@ async def get( """Gets the user activities of a data warehouse which includes running and suspended queries. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param data_warehouse_user_activity_name: The activity name of the data warehouse. + :param data_warehouse_user_activity_name: The activity name of the data warehouse. "current" + Required. :type data_warehouse_user_activity_name: str or ~azure.mgmt.sql.models.DataWarehouseUserActivityName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DataWarehouseUserActivities, or the result of cls(response) + :return: DataWarehouseUserActivities or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DataWarehouseUserActivities - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DataWarehouseUserActivities] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DataWarehouseUserActivities] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -92,7 +94,7 @@ async def get( data_warehouse_user_activity_name=data_warehouse_user_activity_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -100,73 +102,63 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DataWarehouseUserActivities', pipeline_response) + deserialized = self._deserialize("DataWarehouseUserActivities", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataWarehouseUserActivities/{dataWarehouseUserActivityName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataWarehouseUserActivities/{dataWarehouseUserActivityName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.DataWarehouseUserActivitiesListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.DataWarehouseUserActivities"]: """List the user activities of a data warehouse which includes running and suspended queries. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DataWarehouseUserActivitiesListResult or the - result of cls(response) + :return: An iterator like instance of either DataWarehouseUserActivities or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DataWarehouseUserActivitiesListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DataWarehouseUserActivities] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DataWarehouseUserActivitiesListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DataWarehouseUserActivitiesListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -174,17 +166,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -200,10 +182,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -213,8 +193,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataWarehouseUserActivities"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataWarehouseUserActivities"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_advanced_threat_protection_settings_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_advanced_threat_protection_settings_operations.py index dfe7ff976dad8..c0d9c983e4696 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_advanced_threat_protection_settings_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_advanced_threat_protection_settings_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._database_advanced_threat_protection_settings_operations import build_create_or_update_request, build_get_request, build_list_by_database_request -T = TypeVar('T') +from ...operations._database_advanced_threat_protection_settings_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DatabaseAdvancedThreatProtectionSettingsOperations: """ .. warning:: @@ -43,54 +55,45 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.DatabaseAdvancedThreatProtectionListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.DatabaseAdvancedThreatProtection"]: """Gets a list of database's Advanced Threat Protection states. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseAdvancedThreatProtectionListResult or the - result of cls(response) + :return: An iterator like instance of either DatabaseAdvancedThreatProtection or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseAdvancedThreatProtectionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseAdvancedThreatProtectionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseAdvancedThreatProtectionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -98,17 +101,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -124,10 +117,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -137,11 +128,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings"} # type: ignore @distributed_trace_async async def get( @@ -155,35 +144,30 @@ async def get( """Gets a database's Advanced Threat Protection state. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. :type advanced_threat_protection_name: str or ~azure.mgmt.sql.models.AdvancedThreatProtectionName - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseAdvancedThreatProtection, or the result of cls(response) + :return: DatabaseAdvancedThreatProtection or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseAdvancedThreatProtection - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseAdvancedThreatProtection] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseAdvancedThreatProtection] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -191,7 +175,7 @@ async def get( advanced_threat_protection_name=advanced_threat_protection_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -199,27 +183,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseAdvancedThreatProtection', pipeline_response) + deserialized = self._deserialize("DatabaseAdvancedThreatProtection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, @@ -227,43 +209,121 @@ async def create_or_update( database_name: str, advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], parameters: _models.DatabaseAdvancedThreatProtection, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DatabaseAdvancedThreatProtection: """Creates or updates a database's Advanced Threat Protection state. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. :type advanced_threat_protection_name: str or ~azure.mgmt.sql.models.AdvancedThreatProtectionName - :param parameters: The database Advanced Threat Protection state. + :param parameters: The database Advanced Threat Protection state. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseAdvancedThreatProtection - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: DatabaseAdvancedThreatProtection or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseAdvancedThreatProtection + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DatabaseAdvancedThreatProtection: + """Creates or updates a database's Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The database Advanced Threat Protection state. Required. + :type parameters: IO + :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: DatabaseAdvancedThreatProtection or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseAdvancedThreatProtection + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: Union[_models.DatabaseAdvancedThreatProtection, IO], + **kwargs: Any + ) -> _models.DatabaseAdvancedThreatProtection: + """Creates or updates a database's Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The database Advanced Threat Protection state. Is either a model type or a + IO type. Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseAdvancedThreatProtection 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 - :return: DatabaseAdvancedThreatProtection, or the result of cls(response) + :return: DatabaseAdvancedThreatProtection or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseAdvancedThreatProtection - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseAdvancedThreatProtection] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseAdvancedThreatProtection] - _json = self._serialize.body(parameters, 'DatabaseAdvancedThreatProtection') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseAdvancedThreatProtection") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -274,7 +334,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -282,10 +343,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -293,15 +353,14 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('DatabaseAdvancedThreatProtection', pipeline_response) + deserialized = self._deserialize("DatabaseAdvancedThreatProtection", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DatabaseAdvancedThreatProtection', pipeline_response) + deserialized = self._deserialize("DatabaseAdvancedThreatProtection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_advisors_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_advisors_operations.py index 5d904bd4ed32b..a72737975dd75 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_advisors_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_advisors_operations.py @@ -6,9 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, List, Optional, TypeVar - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, List, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -18,10 +24,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._database_advisors_operations import build_get_request, build_list_by_database_request, build_update_request -T = TypeVar('T') +from ...operations._database_advisors_operations import ( + build_get_request, + build_list_by_database_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DatabaseAdvisorsOperations: """ .. warning:: @@ -41,7 +53,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def list_by_database( self, @@ -54,42 +65,36 @@ async def list_by_database( """Gets a list of database advisors. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: list of Advisor, or the result of cls(response) + :return: list of Advisor or the result of cls(response) :rtype: list[~azure.mgmt.sql.models.Advisor] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[List[_models.Advisor]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[List[_models.Advisor]] - request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.list_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -97,66 +102,53 @@ async def list_by_database( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('[Advisor]', pipeline_response) + deserialized = self._deserialize("[Advisor]", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors"} # type: ignore - + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - advisor_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, advisor_name: str, **kwargs: Any ) -> _models.Advisor: """Gets a database advisor. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param advisor_name: The name of the Database Advisor. + :param advisor_name: The name of the Database Advisor. Required. :type advisor_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Advisor, or the result of cls(response) + :return: Advisor or the result of cls(response) :rtype: ~azure.mgmt.sql.models.Advisor - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.Advisor] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.Advisor] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -164,7 +156,7 @@ async def get( advisor_name=advisor_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -172,27 +164,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('Advisor', pipeline_response) + deserialized = self._deserialize("Advisor", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}"} # type: ignore + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}"} # type: ignore - - @distributed_trace_async + @overload async def update( self, resource_group_name: str, @@ -200,42 +190,115 @@ async def update( database_name: str, advisor_name: str, parameters: _models.Advisor, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.Advisor: """Updates a database advisor. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param advisor_name: The name of the Database Advisor. + :param advisor_name: The name of the Database Advisor. Required. :type advisor_name: str - :param parameters: The requested advisor resource state. + :param parameters: The requested advisor resource state. Required. :type parameters: ~azure.mgmt.sql.models.Advisor - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: Advisor or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.Advisor + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + advisor_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.Advisor: + """Updates a database advisor. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advisor_name: The name of the Database Advisor. Required. + :type advisor_name: str + :param parameters: The requested advisor resource state. Required. + :type parameters: IO + :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: Advisor, or the result of cls(response) + :return: Advisor or the result of cls(response) :rtype: ~azure.mgmt.sql.models.Advisor - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace_async + async def update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + advisor_name: str, + parameters: Union[_models.Advisor, IO], + **kwargs: Any + ) -> _models.Advisor: + """Updates a database advisor. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advisor_name: The name of the Database Advisor. Required. + :type advisor_name: str + :param parameters: The requested advisor resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.Advisor 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 + :return: Advisor or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.Advisor + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.Advisor] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.Advisor] - _json = self._serialize.body(parameters, 'Advisor') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "Advisor") request = build_update_request( resource_group_name=resource_group_name, @@ -246,7 +309,8 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -254,22 +318,20 @@ async def update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('Advisor', pipeline_response) + deserialized = self._deserialize("Advisor", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_automatic_tuning_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_automatic_tuning_operations.py index a59e3c9ccb0d7..f2dc38398efaa 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_automatic_tuning_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_automatic_tuning_operations.py @@ -6,9 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -19,9 +25,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._database_automatic_tuning_operations import build_get_request, build_update_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DatabaseAutomaticTuningOperations: """ .. warning:: @@ -41,51 +49,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> _models.DatabaseAutomaticTuning: """Gets a database's automatic tuning. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseAutomaticTuning, or the result of cls(response) + :return: DatabaseAutomaticTuning or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseAutomaticTuning - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseAutomaticTuning] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseAutomaticTuning] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -93,67 +90,132 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseAutomaticTuning', pipeline_response) + deserialized = self._deserialize("DatabaseAutomaticTuning", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/automaticTuning/current"} # type: ignore + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/automaticTuning/current"} # type: ignore - - @distributed_trace_async + @overload async def update( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.DatabaseAutomaticTuning, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DatabaseAutomaticTuning: """Update automatic tuning properties for target database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The requested automatic tuning resource state. + :param parameters: The requested automatic tuning resource state. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseAutomaticTuning - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: DatabaseAutomaticTuning, or the result of cls(response) + :return: DatabaseAutomaticTuning or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseAutomaticTuning - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DatabaseAutomaticTuning: + """Update automatic tuning properties for target database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested automatic tuning resource state. Required. + :type parameters: IO + :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: DatabaseAutomaticTuning or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseAutomaticTuning + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.DatabaseAutomaticTuning, IO], + **kwargs: Any + ) -> _models.DatabaseAutomaticTuning: + """Update automatic tuning properties for target database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested automatic tuning resource state. Is either a model type or a + IO type. Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseAutomaticTuning 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 + :return: DatabaseAutomaticTuning or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseAutomaticTuning + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseAutomaticTuning] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseAutomaticTuning] - _json = self._serialize.body(parameters, 'DatabaseAutomaticTuning') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseAutomaticTuning") request = build_update_request( resource_group_name=resource_group_name, @@ -163,7 +225,8 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -171,22 +234,20 @@ async def update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseAutomaticTuning', pipeline_response) + deserialized = self._deserialize("DatabaseAutomaticTuning", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/automaticTuning/current"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/automaticTuning/current"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_blob_auditing_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_blob_auditing_policies_operations.py index 81a8899b1d42e..1b0856fd3d5e7 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_blob_auditing_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_blob_auditing_policies_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._database_blob_auditing_policies_operations import build_create_or_update_request, build_get_request, build_list_by_database_request -T = TypeVar('T') +from ...operations._database_blob_auditing_policies_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DatabaseBlobAuditingPoliciesOperations: """ .. warning:: @@ -43,54 +55,45 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.DatabaseBlobAuditingPolicyListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.DatabaseBlobAuditingPolicy"]: """Lists auditing settings of a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseBlobAuditingPolicyListResult or the result - of cls(response) + :return: An iterator like instance of either DatabaseBlobAuditingPolicy or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseBlobAuditingPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseBlobAuditingPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseBlobAuditingPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseBlobAuditingPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -98,17 +101,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -124,10 +117,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -137,53 +128,41 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> _models.DatabaseBlobAuditingPolicy: """Gets a database's blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is "default". Note that overriding this default value may result in unsupported behavior. :paramtype blob_auditing_policy_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseBlobAuditingPolicy, or the result of cls(response) + :return: DatabaseBlobAuditingPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseBlobAuditingPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseBlobAuditingPolicy] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseBlobAuditingPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -191,7 +170,7 @@ async def get( subscription_id=self._config.subscription_id, blob_auditing_policy_name=blob_auditing_policy_name, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -199,71 +178,142 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("DatabaseBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.DatabaseBlobAuditingPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DatabaseBlobAuditingPolicy: """Creates or updates a database's blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The database blob auditing policy. + :param parameters: The database blob auditing policy. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseBlobAuditingPolicy + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is "default". Note that overriding this default value may result in unsupported behavior. :paramtype blob_auditing_policy_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseBlobAuditingPolicy, or the result of cls(response) + :return: DatabaseBlobAuditingPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseBlobAuditingPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DatabaseBlobAuditingPolicy: + """Creates or updates a database's blob auditing policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The database blob auditing policy. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is + "default". Note that overriding this default value may result in unsupported behavior. + :paramtype blob_auditing_policy_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: DatabaseBlobAuditingPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseBlobAuditingPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.DatabaseBlobAuditingPolicy, IO], + **kwargs: Any + ) -> _models.DatabaseBlobAuditingPolicy: + """Creates or updates a database's blob auditing policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The database blob auditing policy. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseBlobAuditingPolicy or IO + :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is + "default". Note that overriding this default value may result in unsupported behavior. + :paramtype blob_auditing_policy_name: str + :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 + :return: DatabaseBlobAuditingPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseBlobAuditingPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseBlobAuditingPolicy] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseBlobAuditingPolicy] - _json = self._serialize.body(parameters, 'DatabaseBlobAuditingPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseBlobAuditingPolicy") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -274,7 +324,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -282,10 +333,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -293,15 +343,14 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('DatabaseBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("DatabaseBlobAuditingPolicy", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DatabaseBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("DatabaseBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_columns_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_columns_operations.py index 38b84d28dc70a..de0f2bb2147a8 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_columns_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_columns_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, List, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._database_columns_operations import build_get_request, build_list_by_database_request, build_list_by_table_request -T = TypeVar('T') +from ...operations._database_columns_operations import ( + build_get_request, + build_list_by_database_request, + build_list_by_table_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DatabaseColumnsOperations: """ .. warning:: @@ -43,7 +55,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( self, @@ -56,62 +67,56 @@ def list_by_database( order_by: Optional[List[str]] = None, skiptoken: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable[_models.DatabaseColumnListResult]: + ) -> AsyncIterable["_models.DatabaseColumn"]: """List database columns. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema: Default value is None. + :param schema: Default value is None. :type schema: list[str] - :param table: Default value is None. + :param table: Default value is None. :type table: list[str] - :param column: Default value is None. + :param column: Default value is None. :type column: list[str] - :param order_by: Default value is None. + :param order_by: Default value is None. :type order_by: list[str] :param skiptoken: An opaque token that identifies a starting point in the collection. Default value is None. :type skiptoken: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseColumnListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseColumnListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseColumn or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseColumn] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseColumnListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseColumnListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, schema=schema, table=table, column=column, order_by=order_by, skiptoken=skiptoken, - template_url=self.list_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -119,22 +124,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - schema=schema, - table=table, - column=column, - order_by=order_by, - skiptoken=skiptoken, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -150,10 +140,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -163,11 +151,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/columns"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/columns"} # type: ignore @distributed_trace def list_by_table( @@ -179,46 +165,40 @@ def list_by_table( table_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable[_models.DatabaseColumnListResult]: + ) -> AsyncIterable["_models.DatabaseColumn"]: """List database columns. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseColumnListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseColumnListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseColumn or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseColumn] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseColumnListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseColumnListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_table_request( resource_group_name=resource_group_name, server_name=server_name, @@ -226,9 +206,9 @@ def prepare_request(next_link=None): schema_name=schema_name, table_name=table_name, subscription_id=self._config.subscription_id, - api_version=api_version, filter=filter, - template_url=self.list_by_table.metadata['url'], + api_version=api_version, + template_url=self.list_by_table.metadata["url"], headers=_headers, params=_params, ) @@ -236,20 +216,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_table_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - schema_name=schema_name, - table_name=table_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -265,10 +232,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -278,11 +243,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_table.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns"} # type: ignore + list_by_table.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns"} # type: ignore @distributed_trace_async async def get( @@ -298,38 +261,32 @@ async def get( """Get database column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseColumn, or the result of cls(response) + :return: DatabaseColumn or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseColumn - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseColumn] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseColumn] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -339,7 +296,7 @@ async def get( column_name=column_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -347,22 +304,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseColumn', pipeline_response) + deserialized = self._deserialize("DatabaseColumn", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_extensions_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_extensions_operations.py index 50da49470f499..a3c40f7a05a73 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_extensions_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_extensions_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._database_extensions_operations import build_create_or_update_request_initial, build_get_request, build_list_by_database_request -T = TypeVar('T') +from ...operations._database_extensions_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DatabaseExtensionsOperations: """ .. warning:: @@ -45,47 +57,35 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - extension_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, extension_name: str, **kwargs: Any ) -> None: """Gets a database extension. This will return resource not found as it is not supported. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param extension_name: + :param extension_name: Required. :type extension_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -93,7 +93,7 @@ async def get( # pylint: disable=inconsistent-return-statements extension_name=extension_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -101,10 +101,9 @@ async def get( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -114,8 +113,7 @@ async def get( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions/{extensionName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions/{extensionName}"} # type: ignore async def _create_or_update_initial( self, @@ -123,24 +121,28 @@ async def _create_or_update_initial( server_name: str, database_name: str, extension_name: str, - parameters: _models.DatabaseExtensions, + parameters: Union[_models.DatabaseExtensions, IO], **kwargs: Any ) -> Optional[_models.ImportExportExtensionsOperationResult]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ImportExportExtensionsOperationResult]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ImportExportExtensionsOperationResult]] - _json = self._serialize.body(parameters, 'DatabaseExtensions') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseExtensions") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -149,7 +151,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -157,10 +160,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -169,17 +171,16 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ImportExportExtensionsOperationResult', pipeline_response) + deserialized = self._deserialize("ImportExportExtensionsOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions/{extensionName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions/{extensionName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, @@ -187,24 +188,69 @@ async def begin_create_or_update( database_name: str, extension_name: str, parameters: _models.DatabaseExtensions, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ImportExportExtensionsOperationResult]: """Perform a database extension operation, like polybase import. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param extension_name: + :param extension_name: Required. :type extension_name: str - :param parameters: The database import request parameters. + :param parameters: The database import request parameters. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseExtensions - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 + ImportExportExtensionsOperationResult or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ImportExportExtensionsOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + extension_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ImportExportExtensionsOperationResult]: + """Perform a database extension operation, like polybase import. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param extension_name: Required. + :type extension_name: str + :param parameters: The database import request parameters. Required. + :type parameters: IO + :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 @@ -217,20 +263,59 @@ async def begin_create_or_update( ImportExportExtensionsOperationResult or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ImportExportExtensionsOperationResult] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + extension_name: str, + parameters: Union[_models.DatabaseExtensions, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ImportExportExtensionsOperationResult]: + """Perform a database extension operation, like polybase import. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param extension_name: Required. + :type extension_name: str + :param parameters: The database import request parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseExtensions 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. + :return: An instance of AsyncLROPoller that returns either + ImportExportExtensionsOperationResult or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ImportExportExtensionsOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ImportExportExtensionsOperationResult] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ImportExportExtensionsOperationResult] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -240,87 +325,75 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ImportExportExtensionsOperationResult', pipeline_response) + deserialized = self._deserialize("ImportExportExtensionsOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/extensions/{extensionName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions/{extensionName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ImportExportExtensionsOperationListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ImportExportExtensionsOperationResult"]: """List database extension. This will return an empty list as it is not supported. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ImportExportExtensionsOperationListResult or the + :return: An iterator like instance of either ImportExportExtensionsOperationResult or the result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ImportExportExtensionsOperationListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ImportExportExtensionsOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ImportExportExtensionsOperationListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ImportExportExtensionsOperationListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -328,17 +401,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -354,10 +417,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -367,8 +428,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_operations_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_operations_operations.py index 517dd0a34bd3e..e5cd80e7a5dd6 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_operations_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_operations_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._database_operations_operations import build_cancel_request, build_list_by_database_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DatabaseOperationsOperations: """ .. warning:: @@ -43,47 +51,35 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def cancel( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - operation_id: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, operation_id: str, **kwargs: Any ) -> None: """Cancels the asynchronous operation on the database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param operation_id: The operation identifier. + :param operation_id: The operation identifier. Required. :type operation_id: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_cancel_request( resource_group_name=resource_group_name, server_name=server_name, @@ -91,7 +87,7 @@ async def cancel( # pylint: disable=inconsistent-return-statements operation_id=operation_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.cancel.metadata['url'], + template_url=self.cancel.metadata["url"], headers=_headers, params=_params, ) @@ -99,10 +95,9 @@ async def cancel( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -112,56 +107,45 @@ async def cancel( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - cancel.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/operations/{operationId}/cancel"} # type: ignore - + cancel.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/operations/{operationId}/cancel"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.DatabaseOperationListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.DatabaseOperation"]: """Gets a list of operations performed on the database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseOperationListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseOperationListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseOperation or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseOperation] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseOperationListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseOperationListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -169,17 +153,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -195,10 +169,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -208,8 +180,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/operations"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/operations"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_recommended_actions_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_recommended_actions_operations.py index 52cc2125829f5..289b2e357b380 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_recommended_actions_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_recommended_actions_operations.py @@ -6,9 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, List, Optional, TypeVar - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, List, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -18,10 +24,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._database_recommended_actions_operations import build_get_request, build_list_by_database_advisor_request, build_update_request -T = TypeVar('T') +from ...operations._database_recommended_actions_operations import ( + build_get_request, + build_list_by_database_advisor_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DatabaseRecommendedActionsOperations: """ .. warning:: @@ -41,47 +53,35 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def list_by_database_advisor( - self, - resource_group_name: str, - server_name: str, - database_name: str, - advisor_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, advisor_name: str, **kwargs: Any ) -> List[_models.RecommendedAction]: """Gets list of Database Recommended Actions. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param advisor_name: The name of the Database Advisor. + :param advisor_name: The name of the Database Advisor. Required. :type advisor_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: list of RecommendedAction, or the result of cls(response) + :return: list of RecommendedAction or the result of cls(response) :rtype: list[~azure.mgmt.sql.models.RecommendedAction] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[List[_models.RecommendedAction]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[List[_models.RecommendedAction]] - request = build_list_by_database_advisor_request( resource_group_name=resource_group_name, server_name=server_name, @@ -89,7 +89,7 @@ async def list_by_database_advisor( advisor_name=advisor_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database_advisor.metadata['url'], + template_url=self.list_by_database_advisor.metadata["url"], headers=_headers, params=_params, ) @@ -97,25 +97,23 @@ async def list_by_database_advisor( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('[RecommendedAction]', pipeline_response) + deserialized = self._deserialize("[RecommendedAction]", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - list_by_database_advisor.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions"} # type: ignore - + list_by_database_advisor.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions"} # type: ignore @distributed_trace_async async def get( @@ -130,36 +128,30 @@ async def get( """Gets a database recommended action. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param advisor_name: The name of the Database Advisor. + :param advisor_name: The name of the Database Advisor. Required. :type advisor_name: str - :param recommended_action_name: The name of Database Recommended Action. + :param recommended_action_name: The name of Database Recommended Action. Required. :type recommended_action_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: RecommendedAction, or the result of cls(response) + :return: RecommendedAction or the result of cls(response) :rtype: ~azure.mgmt.sql.models.RecommendedAction - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RecommendedAction] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RecommendedAction] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -168,7 +160,7 @@ async def get( recommended_action_name=recommended_action_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -176,27 +168,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('RecommendedAction', pipeline_response) + deserialized = self._deserialize("RecommendedAction", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions/{recommendedActionName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions/{recommendedActionName}"} # type: ignore - @distributed_trace_async + @overload async def update( self, resource_group_name: str, @@ -205,44 +195,123 @@ async def update( advisor_name: str, recommended_action_name: str, parameters: _models.RecommendedAction, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.RecommendedAction: """Updates a database recommended action. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param advisor_name: The name of the Database Advisor. + :param advisor_name: The name of the Database Advisor. Required. :type advisor_name: str - :param recommended_action_name: The name of Database Recommended Action. + :param recommended_action_name: The name of Database Recommended Action. Required. :type recommended_action_name: str - :param parameters: The requested recommended action resource state. + :param parameters: The requested recommended action resource state. Required. :type parameters: ~azure.mgmt.sql.models.RecommendedAction - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: RecommendedAction or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.RecommendedAction + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + advisor_name: str, + recommended_action_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.RecommendedAction: + """Updates a database recommended action. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advisor_name: The name of the Database Advisor. Required. + :type advisor_name: str + :param recommended_action_name: The name of Database Recommended Action. Required. + :type recommended_action_name: str + :param parameters: The requested recommended action resource state. Required. + :type parameters: IO + :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: RecommendedAction or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.RecommendedAction + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + advisor_name: str, + recommended_action_name: str, + parameters: Union[_models.RecommendedAction, IO], + **kwargs: Any + ) -> _models.RecommendedAction: + """Updates a database recommended action. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advisor_name: The name of the Database Advisor. Required. + :type advisor_name: str + :param recommended_action_name: The name of Database Recommended Action. Required. + :type recommended_action_name: str + :param parameters: The requested recommended action resource state. Is either a model type or a + IO type. Required. + :type parameters: ~azure.mgmt.sql.models.RecommendedAction 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 - :return: RecommendedAction, or the result of cls(response) + :return: RecommendedAction or the result of cls(response) :rtype: ~azure.mgmt.sql.models.RecommendedAction - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.RecommendedAction] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.RecommendedAction] - _json = self._serialize.body(parameters, 'RecommendedAction') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "RecommendedAction") request = build_update_request( resource_group_name=resource_group_name, @@ -254,7 +323,8 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -262,22 +332,20 @@ async def update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('RecommendedAction', pipeline_response) + deserialized = self._deserialize("RecommendedAction", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions/{recommendedActionName}"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions/{recommendedActionName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_schemas_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_schemas_operations.py index bcd03c6ecc2d3..63f50d2e1d9c1 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_schemas_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_schemas_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._database_schemas_operations import build_get_request, build_list_by_database_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DatabaseSchemasOperations: """ .. warning:: @@ -43,7 +51,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( self, @@ -52,50 +59,44 @@ def list_by_database( database_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable[_models.DatabaseSchemaListResult]: + ) -> AsyncIterable["_models.DatabaseSchema"]: """List database schemas. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseSchemaListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseSchemaListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseSchema or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseSchema] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseSchemaListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseSchemaListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, filter=filter, - template_url=self.list_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -103,18 +104,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -130,10 +120,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -143,52 +131,39 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - schema_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, schema_name: str, **kwargs: Any ) -> _models.DatabaseSchema: """Get database schema. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseSchema, or the result of cls(response) + :return: DatabaseSchema or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseSchema - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseSchema] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseSchema] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -196,7 +171,7 @@ async def get( schema_name=schema_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -204,22 +179,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseSchema', pipeline_response) + deserialized = self._deserialize("DatabaseSchema", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_security_alert_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_security_alert_policies_operations.py index 4f7b2c6bad7dc..4f05e18d5a2c4 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_security_alert_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_security_alert_policies_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._database_security_alert_policies_operations import build_create_or_update_request, build_get_request, build_list_by_database_request -T = TypeVar('T') +from ...operations._database_security_alert_policies_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DatabaseSecurityAlertPoliciesOperations: """ .. warning:: @@ -43,7 +55,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -56,34 +67,29 @@ async def get( """Gets a database's security alert policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the security alert policy is defined. + Required. :type database_name: str - :param security_alert_policy_name: The name of the security alert policy. + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseSecurityAlertPolicy, or the result of cls(response) + :return: DatabaseSecurityAlertPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseSecurityAlertPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseSecurityAlertPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseSecurityAlertPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -91,7 +97,7 @@ async def get( security_alert_policy_name=security_alert_policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -99,27 +105,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("DatabaseSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, @@ -127,42 +131,118 @@ async def create_or_update( database_name: str, security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], parameters: _models.DatabaseSecurityAlertPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DatabaseSecurityAlertPolicy: """Creates or updates a database's security alert policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the security alert policy is defined. + Required. :type database_name: str - :param security_alert_policy_name: The name of the security alert policy. + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName - :param parameters: The database security alert policy. + :param parameters: The database security alert policy. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseSecurityAlertPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: DatabaseSecurityAlertPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseSecurityAlertPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DatabaseSecurityAlertPolicy: + """Creates or updates a database's security alert policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database for which the security alert policy is defined. + Required. + :type database_name: str + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. + :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName + :param parameters: The database security alert policy. Required. + :type parameters: IO + :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: DatabaseSecurityAlertPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseSecurityAlertPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], + parameters: Union[_models.DatabaseSecurityAlertPolicy, IO], + **kwargs: Any + ) -> _models.DatabaseSecurityAlertPolicy: + """Creates or updates a database's security alert policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database for which the security alert policy is defined. + Required. + :type database_name: str + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. + :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName + :param parameters: The database security alert policy. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseSecurityAlertPolicy 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 - :return: DatabaseSecurityAlertPolicy, or the result of cls(response) + :return: DatabaseSecurityAlertPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseSecurityAlertPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseSecurityAlertPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseSecurityAlertPolicy] - _json = self._serialize.body(parameters, 'DatabaseSecurityAlertPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseSecurityAlertPolicy") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -173,7 +253,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -181,10 +262,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -192,66 +272,58 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('DatabaseSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("DatabaseSecurityAlertPolicy", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DatabaseSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("DatabaseSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.DatabaseSecurityAlertListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.DatabaseSecurityAlertPolicy"]: """Gets a list of database's security alert policies. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the security alert policy is defined. + Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseSecurityAlertListResult or the result of + :return: An iterator like instance of either DatabaseSecurityAlertPolicy or the result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseSecurityAlertListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseSecurityAlertPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseSecurityAlertListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseSecurityAlertListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -259,17 +331,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -285,10 +347,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -298,8 +358,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_tables_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_tables_operations.py index 944f1868520d1..56f947b139c0d 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_tables_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_tables_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._database_tables_operations import build_get_request, build_list_by_schema_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DatabaseTablesOperations: """ .. warning:: @@ -43,7 +51,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_schema( self, @@ -53,52 +60,47 @@ def list_by_schema( schema_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable[_models.DatabaseTableListResult]: + ) -> AsyncIterable["_models.DatabaseTable"]: """List database tables. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseTableListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseTableListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseTable or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseTable] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseTableListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseTableListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_schema_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, schema_name=schema_name, subscription_id=self._config.subscription_id, - api_version=api_version, filter=filter, - template_url=self.list_by_schema.metadata['url'], + api_version=api_version, + template_url=self.list_by_schema.metadata["url"], headers=_headers, params=_params, ) @@ -106,19 +108,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_schema_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - schema_name=schema_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -134,10 +124,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -147,11 +135,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_schema.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables"} # type: ignore + list_by_schema.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables"} # type: ignore @distributed_trace_async async def get( @@ -166,36 +152,30 @@ async def get( """Get database table. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseTable, or the result of cls(response) + :return: DatabaseTable or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseTable - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseTable] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseTable] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -204,7 +184,7 @@ async def get( table_name=table_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -212,22 +192,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseTable', pipeline_response) + deserialized = self._deserialize("DatabaseTable", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_usages_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_usages_operations.py index f80a90fb1987a..71caf218f4d93 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_usages_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_usages_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,9 +26,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._database_usages_operations import build_list_by_database_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DatabaseUsagesOperations: """ .. warning:: @@ -42,53 +50,43 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.DatabaseUsageListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.DatabaseUsage"]: """Gets database usages. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseUsageListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseUsageListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseUsage or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseUsage] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseUsageListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseUsageListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -96,17 +94,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -122,10 +110,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -135,8 +121,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/usages"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/usages"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_vulnerability_assessment_rule_baselines_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_vulnerability_assessment_rule_baselines_operations.py index 4a86690ae0035..5998756ff6b72 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_vulnerability_assessment_rule_baselines_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_vulnerability_assessment_rule_baselines_operations.py @@ -6,9 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar, Union - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -18,10 +24,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._database_vulnerability_assessment_rule_baselines_operations import build_create_or_update_request, build_delete_request, build_get_request -T = TypeVar('T') +from ...operations._database_vulnerability_assessment_rule_baselines_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DatabaseVulnerabilityAssessmentRuleBaselinesOperations: """ .. warning:: @@ -41,7 +53,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -56,40 +67,36 @@ async def get( """Gets a database's vulnerability assessment rule baseline. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the vulnerability assessment rule - baseline is defined. + baseline is defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param rule_id: The vulnerability assessment rule ID. + :param rule_id: The vulnerability assessment rule ID. Required. :type rule_id: str :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a - baseline on a database level rule and master for server level rule). + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseVulnerabilityAssessmentRuleBaseline, or the result of cls(response) + :return: DatabaseVulnerabilityAssessmentRuleBaseline or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentRuleBaseline] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentRuleBaseline] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -99,7 +106,7 @@ async def get( baseline_name=baseline_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -107,27 +114,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseVulnerabilityAssessmentRuleBaseline', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessmentRuleBaseline", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, @@ -137,48 +142,143 @@ async def create_or_update( rule_id: str, baseline_name: Union[str, "_models.VulnerabilityAssessmentPolicyBaselineName"], parameters: _models.DatabaseVulnerabilityAssessmentRuleBaseline, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DatabaseVulnerabilityAssessmentRuleBaseline: """Creates or updates a database's vulnerability assessment rule baseline. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the vulnerability assessment rule - baseline is defined. + baseline is defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param rule_id: The vulnerability assessment rule ID. + :param rule_id: The vulnerability assessment rule ID. Required. :type rule_id: str :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a - baseline on a database level rule and master for server level rule). + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName - :param parameters: The requested rule baseline resource. + :param parameters: The requested rule baseline resource. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: DatabaseVulnerabilityAssessmentRuleBaseline or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + rule_id: str, + baseline_name: Union[str, "_models.VulnerabilityAssessmentPolicyBaselineName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DatabaseVulnerabilityAssessmentRuleBaseline: + """Creates or updates a database's vulnerability assessment rule baseline. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database for which the vulnerability assessment rule + baseline is defined. Required. + :type database_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param rule_id: The vulnerability assessment rule ID. Required. + :type rule_id: str + :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. + :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName + :param parameters: The requested rule baseline resource. Required. + :type parameters: IO + :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: DatabaseVulnerabilityAssessmentRuleBaseline, or the result of cls(response) + :return: DatabaseVulnerabilityAssessmentRuleBaseline or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + rule_id: str, + baseline_name: Union[str, "_models.VulnerabilityAssessmentPolicyBaselineName"], + parameters: Union[_models.DatabaseVulnerabilityAssessmentRuleBaseline, IO], + **kwargs: Any + ) -> _models.DatabaseVulnerabilityAssessmentRuleBaseline: + """Creates or updates a database's vulnerability assessment rule baseline. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database for which the vulnerability assessment rule + baseline is defined. Required. + :type database_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param rule_id: The vulnerability assessment rule ID. Required. + :type rule_id: str + :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. + :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName + :param parameters: The requested rule baseline resource. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline 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 + :return: DatabaseVulnerabilityAssessmentRuleBaseline or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentRuleBaseline] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentRuleBaseline] - _json = self._serialize.body(parameters, 'DatabaseVulnerabilityAssessmentRuleBaseline') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseVulnerabilityAssessmentRuleBaseline") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -191,7 +291,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -199,25 +300,23 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseVulnerabilityAssessmentRuleBaseline', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessmentRuleBaseline", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -233,40 +332,36 @@ async def delete( # pylint: disable=inconsistent-return-statements """Removes the database's vulnerability assessment rule baseline. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the vulnerability assessment rule - baseline is defined. + baseline is defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param rule_id: The vulnerability assessment rule ID. + :param rule_id: The vulnerability assessment rule ID. Required. :type rule_id: str :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a - baseline on a database level rule and master for server level rule). + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -276,7 +371,7 @@ async def delete( # pylint: disable=inconsistent-return-statements baseline_name=baseline_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -284,10 +379,9 @@ async def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -297,5 +391,4 @@ async def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_vulnerability_assessment_scans_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_vulnerability_assessment_scans_operations.py index e5666e28d4af8..67dc02b1fe4cf 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_vulnerability_assessment_scans_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_vulnerability_assessment_scans_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._database_vulnerability_assessment_scans_operations import build_export_request, build_get_request, build_initiate_scan_request_initial, build_list_by_database_request -T = TypeVar('T') +from ...operations._database_vulnerability_assessment_scans_operations import ( + build_export_request, + build_get_request, + build_initiate_scan_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DatabaseVulnerabilityAssessmentScansOperations: """ .. warning:: @@ -45,7 +58,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - async def _initiate_scan_initial( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, @@ -55,19 +67,16 @@ async def _initiate_scan_initial( # pylint: disable=inconsistent-return-stateme scan_id: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_initiate_scan_request_initial( + request = build_initiate_scan_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -75,7 +84,7 @@ async def _initiate_scan_initial( # pylint: disable=inconsistent-return-stateme scan_id=scan_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._initiate_scan_initial.metadata['url'], + template_url=self._initiate_scan_initial.metadata["url"], headers=_headers, params=_params, ) @@ -83,10 +92,9 @@ async def _initiate_scan_initial( # pylint: disable=inconsistent-return-stateme request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -96,11 +104,10 @@ async def _initiate_scan_initial( # pylint: disable=inconsistent-return-stateme if cls: return cls(pipeline_response, None, {}) - _initiate_scan_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan"} # type: ignore - + _initiate_scan_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan"} # type: ignore @distributed_trace_async - async def begin_initiate_scan( # pylint: disable=inconsistent-return-statements + async def begin_initiate_scan( self, resource_group_name: str, server_name: str, @@ -112,19 +119,17 @@ async def begin_initiate_scan( # pylint: disable=inconsistent-return-statements """Executes a Vulnerability Assessment database scan. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param scan_id: The vulnerability assessment scan Id of the scan to retrieve. + :param scan_id: The vulnerability assessment scan Id of the scan to retrieve. Required. :type scan_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -135,19 +140,16 @@ async def begin_initiate_scan( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._initiate_scan_initial( # type: ignore resource_group_name=resource_group_name, @@ -156,37 +158,33 @@ async def begin_initiate_scan( # pylint: disable=inconsistent-return-statements vulnerability_assessment_name=vulnerability_assessment_name, scan_id=scan_id, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_initiate_scan.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan"} # type: ignore + begin_initiate_scan.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan"} # type: ignore @distributed_trace def list_by_database( @@ -196,41 +194,38 @@ def list_by_database( database_name: str, vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], **kwargs: Any - ) -> AsyncIterable[_models.VulnerabilityAssessmentScanRecordListResult]: + ) -> AsyncIterable["_models.VulnerabilityAssessmentScanRecord"]: """Lists the vulnerability assessment scans of a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VulnerabilityAssessmentScanRecordListResult or the - result of cls(response) + :return: An iterator like instance of either VulnerabilityAssessmentScanRecord or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.VulnerabilityAssessmentScanRecordListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.VulnerabilityAssessmentScanRecord] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VulnerabilityAssessmentScanRecordListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VulnerabilityAssessmentScanRecordListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, @@ -238,7 +233,7 @@ def prepare_request(next_link=None): vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -246,18 +241,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - vulnerability_assessment_name=vulnerability_assessment_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -273,10 +257,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -286,11 +268,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans"} # type: ignore @distributed_trace_async async def get( @@ -305,36 +285,31 @@ async def get( """Gets a vulnerability assessment scan record of a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param scan_id: The vulnerability assessment scan Id of the scan to retrieve. + :param scan_id: The vulnerability assessment scan Id of the scan to retrieve. Required. :type scan_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VulnerabilityAssessmentScanRecord, or the result of cls(response) + :return: VulnerabilityAssessmentScanRecord or the result of cls(response) :rtype: ~azure.mgmt.sql.models.VulnerabilityAssessmentScanRecord - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VulnerabilityAssessmentScanRecord] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VulnerabilityAssessmentScanRecord] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -343,7 +318,7 @@ async def get( scan_id=scan_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -351,25 +326,23 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('VulnerabilityAssessmentScanRecord', pipeline_response) + deserialized = self._deserialize("VulnerabilityAssessmentScanRecord", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}"} # type: ignore @distributed_trace_async async def export( @@ -384,36 +357,31 @@ async def export( """Convert an existing scan result to a human readable format. If already exists nothing happens. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the scanned database. + :param database_name: The name of the scanned database. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param scan_id: The vulnerability assessment scan Id. + :param scan_id: The vulnerability assessment scan Id. Required. :type scan_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseVulnerabilityAssessmentScansExport, or the result of cls(response) + :return: DatabaseVulnerabilityAssessmentScansExport or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentScansExport - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentScansExport] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentScansExport] - request = build_export_request( resource_group_name=resource_group_name, server_name=server_name, @@ -422,7 +390,7 @@ async def export( scan_id=scan_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.export.metadata['url'], + template_url=self.export.metadata["url"], headers=_headers, params=_params, ) @@ -430,10 +398,9 @@ async def export( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -441,15 +408,14 @@ async def export( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('DatabaseVulnerabilityAssessmentScansExport', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessmentScansExport", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DatabaseVulnerabilityAssessmentScansExport', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessmentScansExport", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - export.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/export"} # type: ignore - + export.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/export"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_vulnerability_assessments_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_vulnerability_assessments_operations.py index 7e39edc82ca33..625dc46d0ecc8 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_vulnerability_assessments_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_database_vulnerability_assessments_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._database_vulnerability_assessments_operations import build_create_or_update_request, build_delete_request, build_get_request, build_list_by_database_request -T = TypeVar('T') +from ...operations._database_vulnerability_assessments_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DatabaseVulnerabilityAssessmentsOperations: """ .. warning:: @@ -43,7 +56,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -56,35 +68,30 @@ async def get( """Gets the database's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the vulnerability assessment is - defined. + defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseVulnerabilityAssessment, or the result of cls(response) + :return: DatabaseVulnerabilityAssessment or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessment] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessment] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -92,7 +99,7 @@ async def get( vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -100,27 +107,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, @@ -128,43 +133,120 @@ async def create_or_update( database_name: str, vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], parameters: _models.DatabaseVulnerabilityAssessment, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DatabaseVulnerabilityAssessment: """Creates or updates the database's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the vulnerability assessment is - defined. + defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param parameters: The requested resource. + :param parameters: The requested resource. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: DatabaseVulnerabilityAssessment or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DatabaseVulnerabilityAssessment: + """Creates or updates the database's vulnerability assessment. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database for which the vulnerability assessment is + defined. Required. + :type database_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param parameters: The requested resource. Required. + :type parameters: IO + :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: DatabaseVulnerabilityAssessment, or the result of cls(response) + :return: DatabaseVulnerabilityAssessment or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + parameters: Union[_models.DatabaseVulnerabilityAssessment, IO], + **kwargs: Any + ) -> _models.DatabaseVulnerabilityAssessment: + """Creates or updates the database's vulnerability assessment. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database for which the vulnerability assessment is + defined. Required. + :type database_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param parameters: The requested resource. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment 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 + :return: DatabaseVulnerabilityAssessment or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessment] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessment] - _json = self._serialize.body(parameters, 'DatabaseVulnerabilityAssessment') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseVulnerabilityAssessment") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -175,7 +257,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -183,10 +266,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -194,18 +276,17 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('DatabaseVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessment", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DatabaseVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -219,35 +300,30 @@ async def delete( # pylint: disable=inconsistent-return-statements """Removes the database's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the vulnerability assessment is - defined. + defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -255,7 +331,7 @@ async def delete( # pylint: disable=inconsistent-return-statements vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -263,10 +339,9 @@ async def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -276,57 +351,48 @@ async def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.DatabaseVulnerabilityAssessmentListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.DatabaseVulnerabilityAssessment"]: """Lists the vulnerability assessment policies associated with a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the vulnerability assessment policies - are defined. + are defined. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseVulnerabilityAssessmentListResult or the - result of cls(response) + :return: An iterator like instance of either DatabaseVulnerabilityAssessment or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -334,17 +400,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -360,10 +416,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -373,8 +427,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_databases_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_databases_operations.py index 8c9b58526bc14..5e53f284b138e 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_databases_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_databases_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,29 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._databases_operations import build_create_or_update_request_initial, build_delete_request_initial, build_export_request_initial, build_failover_request_initial, build_get_request, build_import_method_request_initial, build_list_by_elastic_pool_request, build_list_by_server_request, build_list_inaccessible_by_server_request, build_list_metric_definitions_request, build_list_metrics_request, build_pause_request_initial, build_rename_request, build_resume_request_initial, build_update_request_initial, build_upgrade_data_warehouse_request_initial -T = TypeVar('T') +from ...operations._databases_operations import ( + build_create_or_update_request, + build_delete_request, + build_export_request, + build_failover_request, + build_get_request, + build_import_method_request, + build_list_by_elastic_pool_request, + build_list_by_server_request, + build_list_inaccessible_by_server_request, + build_list_metric_definitions_request, + build_list_metrics_request, + build_pause_request, + build_rename_request, + build_resume_request, + build_update_request, + build_upgrade_data_warehouse_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DatabasesOperations: # pylint: disable=too-many-public-methods """ .. warning:: @@ -45,56 +70,47 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_metrics( - self, - resource_group_name: str, - server_name: str, - database_name: str, - filter: str, - **kwargs: Any - ) -> AsyncIterable[_models.MetricListResult]: + self, resource_group_name: str, server_name: str, database_name: str, filter: str, **kwargs: Any + ) -> AsyncIterable["_models.Metric"]: """Returns database metrics. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param filter: An OData filter expression that describes a subset of metrics to return. + Required. :type filter: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either MetricListResult or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.MetricListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Metric or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.Metric] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.MetricListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.MetricListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_metrics_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, - api_version=api_version, + subscription_id=self._config.subscription_id, filter=filter, - template_url=self.list_metrics.metadata['url'], + api_version=api_version, + template_url=self.list_metrics.metadata["url"], headers=_headers, params=_params, ) @@ -102,18 +118,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_metrics_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -129,10 +134,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -142,59 +145,47 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_metrics.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metrics"} # type: ignore + list_metrics.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metrics"} # type: ignore @distributed_trace def list_metric_definitions( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.MetricDefinitionListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.MetricDefinition"]: """Returns database metric definitions. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either MetricDefinitionListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.MetricDefinitionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either MetricDefinition or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.MetricDefinition] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.MetricDefinitionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.MetricDefinitionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_metric_definitions_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_metric_definitions.metadata['url'], + template_url=self.list_metric_definitions.metadata["url"], headers=_headers, params=_params, ) @@ -202,17 +193,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_metric_definitions_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -228,10 +209,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -241,57 +220,47 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_metric_definitions.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metricDefinitions"} # type: ignore + list_metric_definitions.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metricDefinitions"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - skip_token: Optional[str] = None, - **kwargs: Any - ) -> AsyncIterable[_models.DatabaseListResult]: + self, resource_group_name: str, server_name: str, skip_token: Optional[str] = None, **kwargs: Any + ) -> AsyncIterable["_models.Database"]: """Gets a list of databases. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param skip_token: Default value is None. + :param skip_token: Default value is None. :type skip_token: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseListResult or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Database or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.Database] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, - api_version=api_version, skip_token=skip_token, - template_url=self.list_by_server.metadata['url'], + api_version=api_version, + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -299,17 +268,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - skip_token=skip_token, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -325,10 +284,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -338,56 +295,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> _models.Database: """Gets a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Database, or the result of cls(response) + :return: Database or the result of cls(response) :rtype: ~azure.mgmt.sql.models.Database - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.Database] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.Database] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -395,49 +340,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, database_name: str, - parameters: _models.Database, + parameters: Union[_models.Database, IO], **kwargs: Any ) -> Optional[_models.Database]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.Database]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.Database]] - _json = self._serialize.body(parameters, 'Database') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "Database") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -445,7 +392,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -453,10 +401,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -465,42 +412,43 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.Database, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.Database]: """Creates a new database or updates an existing database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The requested database resource state. + :param parameters: The requested database resource state. Required. :type parameters: ~azure.mgmt.sql.models.Database - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -512,20 +460,94 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either Database or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.Database] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.Database]: + """Creates a new database or updates an existing database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested database resource state. Required. + :type parameters: IO + :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 Database or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.Database] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.Database, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.Database]: + """Creates a new database or updates an existing database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested database resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.Database 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. + :return: An instance of AsyncLROPoller that returns either Database or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.Database] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.Database] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.Database] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -534,66 +556,55 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -601,10 +612,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -614,29 +624,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes the database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -647,80 +649,77 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore async def _update_initial( self, resource_group_name: str, server_name: str, database_name: str, - parameters: _models.DatabaseUpdate, + parameters: Union[_models.DatabaseUpdate, IO], **kwargs: Any ) -> Optional[_models.Database]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.Database]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.Database]] - _json = self._serialize.body(parameters, 'DatabaseUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -728,7 +727,8 @@ async def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -736,10 +736,9 @@ async def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -748,39 +747,40 @@ async def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_update( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.DatabaseUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.Database]: """Updates an existing database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The requested database resource state. + :param parameters: The requested database resource state. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseUpdate - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -792,20 +792,94 @@ async def begin_update( :return: An instance of AsyncLROPoller that returns either Database or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.Database] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.Database]: + """Updates an existing database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested database resource state. Required. + :type parameters: IO + :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 Database or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.Database] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.DatabaseUpdate, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.Database]: + """Updates an existing database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested database resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseUpdate 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. + :return: An instance of AsyncLROPoller that returns either Database or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.Database] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.Database] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.Database] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -814,63 +888,63 @@ async def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore async def _export_initial( self, resource_group_name: str, server_name: str, database_name: str, - parameters: _models.ExportDatabaseDefinition, + parameters: Union[_models.ExportDatabaseDefinition, IO], **kwargs: Any ) -> Optional[_models.ImportExportOperationResult]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ImportExportOperationResult]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ImportExportOperationResult]] - _json = self._serialize.body(parameters, 'ExportDatabaseDefinition') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ExportDatabaseDefinition") - request = build_export_request_initial( + request = build_export_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -878,7 +952,8 @@ async def _export_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._export_initial.metadata['url'], + content=_content, + template_url=self._export_initial.metadata["url"], headers=_headers, params=_params, ) @@ -886,10 +961,9 @@ async def _export_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -898,39 +972,40 @@ async def _export_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ImportExportOperationResult', pipeline_response) + deserialized = self._deserialize("ImportExportOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _export_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/export"} # type: ignore + _export_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/export"} # type: ignore - - @distributed_trace_async + @overload async def begin_export( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.ExportDatabaseDefinition, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ImportExportOperationResult]: """Exports a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The database export request parameters. + :param parameters: The database export request parameters. Required. :type parameters: ~azure.mgmt.sql.models.ExportDatabaseDefinition - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -942,20 +1017,94 @@ async def begin_export( :return: An instance of AsyncLROPoller that returns either ImportExportOperationResult or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_export( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ImportExportOperationResult]: + """Exports a database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The database export request parameters. Required. + :type parameters: IO + :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 ImportExportOperationResult or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_export( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.ExportDatabaseDefinition, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ImportExportOperationResult]: + """Exports a database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The database export request parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ExportDatabaseDefinition 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. + :return: An instance of AsyncLROPoller that returns either ImportExportOperationResult or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ImportExportOperationResult] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ImportExportOperationResult] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._export_initial( # type: ignore resource_group_name=resource_group_name, @@ -964,39 +1113,35 @@ async def begin_export( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ImportExportOperationResult', pipeline_response) + deserialized = self._deserialize("ImportExportOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_export.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/export"} # type: ignore + begin_export.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/export"} # type: ignore async def _failover_initial( # pylint: disable=inconsistent-return-statements self, @@ -1006,26 +1151,23 @@ async def _failover_initial( # pylint: disable=inconsistent-return-statements replica_type: Optional[Union[str, "_models.ReplicaType"]] = None, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_failover_request_initial( + request = build_failover_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, replica_type=replica_type, - template_url=self._failover_initial.metadata['url'], + api_version=api_version, + template_url=self._failover_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1033,10 +1175,9 @@ async def _failover_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1046,11 +1187,10 @@ async def _failover_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _failover_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/failover"} # type: ignore - + _failover_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/failover"} # type: ignore @distributed_trace_async - async def begin_failover( # pylint: disable=inconsistent-return-statements + async def begin_failover( self, resource_group_name: str, server_name: str, @@ -1061,17 +1201,15 @@ async def begin_failover( # pylint: disable=inconsistent-return-statements """Failovers a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database to failover. + :param database_name: The name of the database to failover. Required. :type database_name: str - :param replica_type: The type of replica to be failed over. Default value is None. + :param replica_type: The type of replica to be failed over. Known values are: "Primary" and + "ReadableSecondary". Default value is None. :type replica_type: str or ~azure.mgmt.sql.models.ReplicaType - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1082,19 +1220,16 @@ async def begin_failover( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._failover_initial( # type: ignore resource_group_name=resource_group_name, @@ -1102,61 +1237,61 @@ async def begin_failover( # pylint: disable=inconsistent-return-statements database_name=database_name, replica_type=replica_type, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_failover.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/failover"} # type: ignore + begin_failover.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/failover"} # type: ignore async def _import_method_initial( self, resource_group_name: str, server_name: str, database_name: str, - parameters: _models.ImportExistingDatabaseDefinition, + parameters: Union[_models.ImportExistingDatabaseDefinition, IO], **kwargs: Any ) -> Optional[_models.ImportExportOperationResult]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ImportExportOperationResult]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ImportExportOperationResult]] - _json = self._serialize.body(parameters, 'ImportExistingDatabaseDefinition') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ImportExistingDatabaseDefinition") - request = build_import_method_request_initial( + request = build_import_method_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -1164,7 +1299,8 @@ async def _import_method_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._import_method_initial.metadata['url'], + content=_content, + template_url=self._import_method_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1172,10 +1308,9 @@ async def _import_method_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1184,39 +1319,40 @@ async def _import_method_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ImportExportOperationResult', pipeline_response) + deserialized = self._deserialize("ImportExportOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _import_method_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/import"} # type: ignore - + _import_method_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/import"} # type: ignore - @distributed_trace_async + @overload async def begin_import_method( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.ImportExistingDatabaseDefinition, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ImportExportOperationResult]: """Imports a bacpac into a new database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The database import request parameters. + :param parameters: The database import request parameters. Required. :type parameters: ~azure.mgmt.sql.models.ImportExistingDatabaseDefinition - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -1228,20 +1364,94 @@ async def begin_import_method( :return: An instance of AsyncLROPoller that returns either ImportExportOperationResult or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_import_method( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ImportExportOperationResult]: + """Imports a bacpac into a new database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The database import request parameters. Required. + :type parameters: IO + :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 ImportExportOperationResult or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_import_method( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.ImportExistingDatabaseDefinition, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ImportExportOperationResult]: + """Imports a bacpac into a new database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The database import request parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ImportExistingDatabaseDefinition 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. + :return: An instance of AsyncLROPoller that returns either ImportExportOperationResult or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ImportExportOperationResult] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ImportExportOperationResult] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._import_method_initial( # type: ignore resource_group_name=resource_group_name, @@ -1250,81 +1460,144 @@ async def begin_import_method( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ImportExportOperationResult', pipeline_response) + deserialized = self._deserialize("ImportExportOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_import_method.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/import"} # type: ignore + begin_import_method.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/import"} # type: ignore - @distributed_trace_async + @overload async def rename( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.ResourceMoveDefinition, + *, + content_type: str = "application/json", **kwargs: Any ) -> None: """Renames a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database to rename. + :param database_name: The name of the database to rename. Required. :type database_name: str - :param parameters: The resource move definition for renaming this database. + :param parameters: The resource move definition for renaming this database. Required. :type parameters: ~azure.mgmt.sql.models.ResourceMoveDefinition - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def rename( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> None: + """Renames a database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database to rename. Required. + :type database_name: str + :param parameters: The resource move definition for renaming this database. Required. + :type parameters: IO + :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: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace_async + async def rename( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.ResourceMoveDefinition, IO], + **kwargs: Any + ) -> None: + """Renames a database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database to rename. Required. + :type database_name: str + :param parameters: The resource move definition for renaming this database. Is either a model + type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ResourceMoveDefinition 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 + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'ResourceMoveDefinition') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ResourceMoveDefinition") request = build_rename_request( resource_group_name=resource_group_name, @@ -1334,7 +1607,8 @@ async def rename( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self.rename.metadata['url'], + content=_content, + template_url=self.rename.metadata["url"], headers=_headers, params=_params, ) @@ -1342,10 +1616,9 @@ async def rename( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -1355,35 +1628,27 @@ async def rename( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - rename.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/move"} # type: ignore - + rename.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/move"} # type: ignore async def _pause_initial( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> Optional[_models.Database]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.Database]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.Database]] - - request = build_pause_request_initial( + request = build_pause_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._pause_initial.metadata['url'], + template_url=self._pause_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1391,10 +1656,9 @@ async def _pause_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1403,36 +1667,28 @@ async def _pause_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _pause_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/pause"} # type: ignore - + _pause_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/pause"} # type: ignore @distributed_trace_async async def begin_pause( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> AsyncLROPoller[_models.Database]: """Pauses a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database to be paused. + :param database_name: The name of the database to be paused. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1444,85 +1700,71 @@ async def begin_pause( :return: An instance of AsyncLROPoller that returns either Database or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.Database] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.Database] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.Database] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._pause_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_pause.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/pause"} # type: ignore + begin_pause.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/pause"} # type: ignore async def _resume_initial( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> Optional[_models.Database]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.Database]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.Database]] - - request = build_resume_request_initial( + request = build_resume_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._resume_initial.metadata['url'], + template_url=self._resume_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1530,10 +1772,9 @@ async def _resume_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1542,36 +1783,28 @@ async def _resume_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _resume_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/resume"} # type: ignore - + _resume_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/resume"} # type: ignore @distributed_trace_async async def begin_resume( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> AsyncLROPoller[_models.Database]: """Resumes a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database to be resumed. + :param database_name: The name of the database to be resumed. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1583,85 +1816,71 @@ async def begin_resume( :return: An instance of AsyncLROPoller that returns either Database or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.Database] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.Database] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.Database] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._resume_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_resume.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/resume"} # type: ignore + begin_resume.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/resume"} # type: ignore async def _upgrade_data_warehouse_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_upgrade_data_warehouse_request_initial( + request = build_upgrade_data_warehouse_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._upgrade_data_warehouse_initial.metadata['url'], + template_url=self._upgrade_data_warehouse_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1669,10 +1888,9 @@ async def _upgrade_data_warehouse_initial( # pylint: disable=inconsistent-retur request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1682,29 +1900,21 @@ async def _upgrade_data_warehouse_initial( # pylint: disable=inconsistent-retur if cls: return cls(pipeline_response, None, {}) - _upgrade_data_warehouse_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/upgradeDataWarehouse"} # type: ignore - + _upgrade_data_warehouse_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/upgradeDataWarehouse"} # type: ignore @distributed_trace_async - async def begin_upgrade_data_warehouse( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + async def begin_upgrade_data_warehouse( + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Upgrades a data warehouse. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database to be upgraded. + :param database_name: The name of the database to be upgraded. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1715,102 +1925,87 @@ async def begin_upgrade_data_warehouse( # pylint: disable=inconsistent-return-s 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._upgrade_data_warehouse_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_upgrade_data_warehouse.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/upgradeDataWarehouse"} # type: ignore + begin_upgrade_data_warehouse.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/upgradeDataWarehouse"} # type: ignore @distributed_trace def list_by_elastic_pool( - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.DatabaseListResult]: + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any + ) -> AsyncIterable["_models.Database"]: """Gets a list of databases in an elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool. + :param elastic_pool_name: The name of the elastic pool. Required. :type elastic_pool_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseListResult or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Database or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.Database] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_elastic_pool_request( resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_elastic_pool.metadata['url'], + template_url=self.list_by_elastic_pool.metadata["url"], headers=_headers, params=_params, ) @@ -1818,17 +2013,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_elastic_pool_request( - resource_group_name=resource_group_name, - server_name=server_name, - elastic_pool_name=elastic_pool_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1844,10 +2029,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1857,53 +2040,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_elastic_pool.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/databases"} # type: ignore + list_by_elastic_pool.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/databases"} # type: ignore @distributed_trace def list_inaccessible_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.DatabaseListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.Database"]: """Gets a list of inaccessible databases in a logical server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseListResult or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Database or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.Database] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_inaccessible_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_inaccessible_by_server.metadata['url'], + template_url=self.list_inaccessible_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -1911,16 +2085,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_inaccessible_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1936,10 +2101,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1949,8 +2112,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_inaccessible_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/inaccessibleDatabases"} # type: ignore + list_inaccessible_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/inaccessibleDatabases"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_deleted_servers_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_deleted_servers_operations.py index 9385489873a70..b94a79ec4af34 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_deleted_servers_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_deleted_servers_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._deleted_servers_operations import build_get_request, build_list_by_location_request, build_list_request, build_recover_request_initial -T = TypeVar('T') +from ...operations._deleted_servers_operations import ( + build_get_request, + build_list_by_location_request, + build_list_request, + build_recover_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DeletedServersOperations: """ .. warning:: @@ -45,40 +58,31 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace - def list( - self, - **kwargs: Any - ) -> AsyncIterable[_models.DeletedServerListResult]: + def list(self, **kwargs: Any) -> AsyncIterable["_models.DeletedServer"]: """Gets a list of all deleted servers in a subscription. - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DeletedServerListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DeletedServerListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DeletedServer or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DeletedServer] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DeletedServerListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DeletedServerListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_request( subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list.metadata['url'], + template_url=self.list.metadata["url"], headers=_headers, params=_params, ) @@ -86,14 +90,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_request( - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -109,10 +106,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -122,51 +117,38 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/deletedServers"} # type: ignore + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/deletedServers"} # type: ignore @distributed_trace_async - async def get( - self, - location_name: str, - deleted_server_name: str, - **kwargs: Any - ) -> _models.DeletedServer: + async def get(self, location_name: str, deleted_server_name: str, **kwargs: Any) -> _models.DeletedServer: """Gets a deleted server. - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param deleted_server_name: The name of the deleted server. + :param deleted_server_name: The name of the deleted server. Required. :type deleted_server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DeletedServer, or the result of cls(response) + :return: DeletedServer or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DeletedServer - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DeletedServer] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DeletedServer] - request = build_get_request( location_name=location_name, deleted_server_name=deleted_server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -174,63 +156,52 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DeletedServer', pipeline_response) + deserialized = self._deserialize("DeletedServer", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers/{deletedServerName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers/{deletedServerName}"} # type: ignore @distributed_trace - def list_by_location( - self, - location_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.DeletedServerListResult]: + def list_by_location(self, location_name: str, **kwargs: Any) -> AsyncIterable["_models.DeletedServer"]: """Gets a list of deleted servers for a location. - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DeletedServerListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DeletedServerListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DeletedServer or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DeletedServer] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DeletedServerListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DeletedServerListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_location_request( location_name=location_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_location.metadata['url'], + template_url=self.list_by_location.metadata["url"], headers=_headers, params=_params, ) @@ -238,15 +209,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_location_request( - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -262,10 +225,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -275,36 +236,28 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers"} # type: ignore + list_by_location.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers"} # type: ignore async def _recover_initial( - self, - location_name: str, - deleted_server_name: str, - **kwargs: Any + self, location_name: str, deleted_server_name: str, **kwargs: Any ) -> Optional[_models.DeletedServer]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.DeletedServer]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.DeletedServer]] - - request = build_recover_request_initial( + request = build_recover_request( location_name=location_name, deleted_server_name=deleted_server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._recover_initial.metadata['url'], + template_url=self._recover_initial.metadata["url"], headers=_headers, params=_params, ) @@ -312,10 +265,9 @@ async def _recover_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -324,32 +276,25 @@ async def _recover_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('DeletedServer', pipeline_response) + deserialized = self._deserialize("DeletedServer", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _recover_initial.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers/{deletedServerName}/recover"} # type: ignore - + _recover_initial.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers/{deletedServerName}/recover"} # type: ignore @distributed_trace_async async def begin_recover( - self, - location_name: str, - deleted_server_name: str, - **kwargs: Any + self, location_name: str, deleted_server_name: str, **kwargs: Any ) -> AsyncLROPoller[_models.DeletedServer]: """Recovers a deleted server. - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param deleted_server_name: The name of the deleted server. + :param deleted_server_name: The name of the deleted server. Required. :type deleted_server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -361,54 +306,47 @@ async def begin_recover( :return: An instance of AsyncLROPoller that returns either DeletedServer or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.DeletedServer] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DeletedServer] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DeletedServer] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._recover_initial( # type: ignore location_name=location_name, deleted_server_name=deleted_server_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('DeletedServer', pipeline_response) + deserialized = self._deserialize("DeletedServer", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_recover.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers/{deletedServerName}/recover"} # type: ignore + begin_recover.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers/{deletedServerName}/recover"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_distributed_availability_groups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_distributed_availability_groups_operations.py index 962ca514f40b0..051c34ed467ff 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_distributed_availability_groups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_distributed_availability_groups_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,18 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._distributed_availability_groups_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_instance_request, build_update_request_initial -T = TypeVar('T') +from ...operations._distributed_availability_groups_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_instance_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class DistributedAvailabilityGroupsOperations: """ .. warning:: @@ -45,50 +59,42 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.DistributedAvailabilityGroupsListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.DistributedAvailabilityGroup"]: """Gets a list of a distributed availability groups in instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DistributedAvailabilityGroupsListResult or the - result of cls(response) + :return: An iterator like instance of either DistributedAvailabilityGroup or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DistributedAvailabilityGroupsListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DistributedAvailabilityGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DistributedAvailabilityGroupsListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DistributedAvailabilityGroupsListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -96,16 +102,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -121,10 +118,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -134,11 +129,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups"} # type: ignore @distributed_trace_async async def get( @@ -151,39 +144,33 @@ async def get( """Gets a distributed availability group info. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param distributed_availability_group_name: The distributed availability group name. + :param distributed_availability_group_name: The distributed availability group name. Required. :type distributed_availability_group_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DistributedAvailabilityGroup, or the result of cls(response) + :return: DistributedAvailabilityGroup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DistributedAvailabilityGroup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DistributedAvailabilityGroup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DistributedAvailabilityGroup] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, distributed_availability_group_name=distributed_availability_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -191,49 +178,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DistributedAvailabilityGroup', pipeline_response) + deserialized = self._deserialize("DistributedAvailabilityGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, distributed_availability_group_name: str, - parameters: _models.DistributedAvailabilityGroup, + parameters: Union[_models.DistributedAvailabilityGroup, IO], **kwargs: Any ) -> Optional[_models.DistributedAvailabilityGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.DistributedAvailabilityGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.DistributedAvailabilityGroup]] - _json = self._serialize.body(parameters, 'DistributedAvailabilityGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DistributedAvailabilityGroup") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, distributed_availability_group_name=distributed_availability_group_name, @@ -241,7 +230,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -249,10 +239,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -261,42 +250,82 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('DistributedAvailabilityGroup', pipeline_response) + deserialized = self._deserialize("DistributedAvailabilityGroup", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DistributedAvailabilityGroup', pipeline_response) + deserialized = self._deserialize("DistributedAvailabilityGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, distributed_availability_group_name: str, parameters: _models.DistributedAvailabilityGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.DistributedAvailabilityGroup]: """Creates a distributed availability group between Sql On-Prem and Sql Managed Instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param distributed_availability_group_name: The distributed availability group name. + :param distributed_availability_group_name: The distributed availability group name. Required. :type distributed_availability_group_name: str - :param parameters: The distributed availability group info. + :param parameters: The distributed availability group info. Required. :type parameters: ~azure.mgmt.sql.models.DistributedAvailabilityGroup - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 DistributedAvailabilityGroup or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.DistributedAvailabilityGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + distributed_availability_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.DistributedAvailabilityGroup]: + """Creates a distributed availability group between Sql On-Prem and Sql Managed Instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param distributed_availability_group_name: The distributed availability group name. Required. + :type distributed_availability_group_name: str + :param parameters: The distributed availability group info. Required. + :type parameters: IO + :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 @@ -308,20 +337,55 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either DistributedAvailabilityGroup or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.DistributedAvailabilityGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + distributed_availability_group_name: str, + parameters: Union[_models.DistributedAvailabilityGroup, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.DistributedAvailabilityGroup]: + """Creates a distributed availability group between Sql On-Prem and Sql Managed Instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param distributed_availability_group_name: The distributed availability group name. Required. + :type distributed_availability_group_name: str + :param parameters: The distributed availability group info. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.DistributedAvailabilityGroup 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. + :return: An instance of AsyncLROPoller that returns either DistributedAvailabilityGroup or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.DistributedAvailabilityGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DistributedAvailabilityGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DistributedAvailabilityGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -330,39 +394,35 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('DistributedAvailabilityGroup', pipeline_response) + deserialized = self._deserialize("DistributedAvailabilityGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements self, @@ -371,25 +431,22 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements distributed_availability_group_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, distributed_availability_group_name=distributed_availability_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -397,10 +454,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -410,11 +466,10 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements + async def begin_delete( self, resource_group_name: str, managed_instance_name: str, @@ -424,15 +479,12 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements """Drops a distributed availability group between Sql On-Prem and Sql Managed Instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param distributed_availability_group_name: The distributed availability group name. + :param distributed_availability_group_name: The distributed availability group name. Required. :type distributed_availability_group_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -443,80 +495,77 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, distributed_availability_group_name=distributed_availability_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore async def _update_initial( self, resource_group_name: str, managed_instance_name: str, distributed_availability_group_name: str, - parameters: _models.DistributedAvailabilityGroup, + parameters: Union[_models.DistributedAvailabilityGroup, IO], **kwargs: Any ) -> Optional[_models.DistributedAvailabilityGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.DistributedAvailabilityGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.DistributedAvailabilityGroup]] - _json = self._serialize.body(parameters, 'DistributedAvailabilityGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DistributedAvailabilityGroup") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, distributed_availability_group_name=distributed_availability_group_name, @@ -524,7 +573,8 @@ async def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -532,10 +582,9 @@ async def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -544,39 +593,40 @@ async def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('DistributedAvailabilityGroup', pipeline_response) + deserialized = self._deserialize("DistributedAvailabilityGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_update( self, resource_group_name: str, managed_instance_name: str, distributed_availability_group_name: str, parameters: _models.DistributedAvailabilityGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.DistributedAvailabilityGroup]: """Updates a distributed availability group replication mode. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param distributed_availability_group_name: The distributed availability group name. + :param distributed_availability_group_name: The distributed availability group name. Required. :type distributed_availability_group_name: str - :param parameters: The distributed availability group info. + :param parameters: The distributed availability group info. Required. :type parameters: ~azure.mgmt.sql.models.DistributedAvailabilityGroup - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -588,20 +638,94 @@ async def begin_update( :return: An instance of AsyncLROPoller that returns either DistributedAvailabilityGroup or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.DistributedAvailabilityGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + distributed_availability_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.DistributedAvailabilityGroup]: + """Updates a distributed availability group replication mode. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param distributed_availability_group_name: The distributed availability group name. Required. + :type distributed_availability_group_name: str + :param parameters: The distributed availability group info. Required. + :type parameters: IO + :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 DistributedAvailabilityGroup or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.DistributedAvailabilityGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + distributed_availability_group_name: str, + parameters: Union[_models.DistributedAvailabilityGroup, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.DistributedAvailabilityGroup]: + """Updates a distributed availability group replication mode. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param distributed_availability_group_name: The distributed availability group name. Required. + :type distributed_availability_group_name: str + :param parameters: The distributed availability group info. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.DistributedAvailabilityGroup 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. + :return: An instance of AsyncLROPoller that returns either DistributedAvailabilityGroup or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.DistributedAvailabilityGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DistributedAvailabilityGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DistributedAvailabilityGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -610,36 +734,32 @@ async def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('DistributedAvailabilityGroup', pipeline_response) + deserialized = self._deserialize("DistributedAvailabilityGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_elastic_pool_activities_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_elastic_pool_activities_operations.py index df86ed64ae956..9e2faee97b5f7 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_elastic_pool_activities_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_elastic_pool_activities_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,9 +26,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._elastic_pool_activities_operations import build_list_by_elastic_pool_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ElasticPoolActivitiesOperations: """ .. warning:: @@ -42,54 +50,44 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_elastic_pool( - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ElasticPoolActivityListResult]: + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ElasticPoolActivity"]: """Returns elastic pool activities. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param elastic_pool_name: The name of the elastic pool for which to get the current activity. + Required. :type elastic_pool_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ElasticPoolActivityListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ElasticPoolActivityListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ElasticPoolActivity or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ElasticPoolActivity] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ElasticPoolActivityListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ElasticPoolActivityListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_elastic_pool_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_elastic_pool.metadata['url'], + template_url=self.list_by_elastic_pool.metadata["url"], headers=_headers, params=_params, ) @@ -97,17 +95,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_elastic_pool_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - elastic_pool_name=elastic_pool_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -123,10 +111,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -136,8 +122,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_elastic_pool.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/elasticPoolActivity"} # type: ignore + list_by_elastic_pool.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/elasticPoolActivity"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_elastic_pool_database_activities_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_elastic_pool_database_activities_operations.py index 3adf0d08508eb..c52763f74e5fa 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_elastic_pool_database_activities_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_elastic_pool_database_activities_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,9 +26,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._elastic_pool_database_activities_operations import build_list_by_elastic_pool_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ElasticPoolDatabaseActivitiesOperations: """ .. warning:: @@ -42,54 +50,45 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_elastic_pool( - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ElasticPoolDatabaseActivityListResult]: + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ElasticPoolDatabaseActivity"]: """Returns activity on databases inside of an elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool. + :param elastic_pool_name: The name of the elastic pool. Required. :type elastic_pool_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ElasticPoolDatabaseActivityListResult or the - result of cls(response) + :return: An iterator like instance of either ElasticPoolDatabaseActivity or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ElasticPoolDatabaseActivityListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ElasticPoolDatabaseActivity] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ElasticPoolDatabaseActivityListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ElasticPoolDatabaseActivityListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_elastic_pool_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_elastic_pool.metadata['url'], + template_url=self.list_by_elastic_pool.metadata["url"], headers=_headers, params=_params, ) @@ -97,17 +96,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_elastic_pool_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - elastic_pool_name=elastic_pool_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -123,10 +112,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -136,8 +123,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_elastic_pool.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/elasticPoolDatabaseActivity"} # type: ignore + list_by_elastic_pool.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/elasticPoolDatabaseActivity"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_elastic_pool_operations_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_elastic_pool_operations_operations.py index 46d061af15992..2f00e4f8aaf5e 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_elastic_pool_operations_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_elastic_pool_operations_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._elastic_pool_operations_operations import build_cancel_request, build_list_by_elastic_pool_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ElasticPoolOperationsOperations: """ .. warning:: @@ -43,47 +51,35 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def cancel( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - operation_id: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, elastic_pool_name: str, operation_id: str, **kwargs: Any ) -> None: """Cancels the asynchronous operation on the elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: + :param elastic_pool_name: Required. :type elastic_pool_name: str - :param operation_id: The operation identifier. + :param operation_id: The operation identifier. Required. :type operation_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_cancel_request( resource_group_name=resource_group_name, server_name=server_name, @@ -91,7 +87,7 @@ async def cancel( # pylint: disable=inconsistent-return-statements operation_id=operation_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.cancel.metadata['url'], + template_url=self.cancel.metadata["url"], headers=_headers, params=_params, ) @@ -99,10 +95,9 @@ async def cancel( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -112,56 +107,46 @@ async def cancel( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - cancel.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/operations/{operationId}/cancel"} # type: ignore - + cancel.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/operations/{operationId}/cancel"} # type: ignore @distributed_trace def list_by_elastic_pool( - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ElasticPoolOperationListResult]: + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ElasticPoolOperation"]: """Gets a list of operations performed on the elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: + :param elastic_pool_name: Required. :type elastic_pool_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ElasticPoolOperationListResult or the result of + :return: An iterator like instance of either ElasticPoolOperation or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ElasticPoolOperationListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ElasticPoolOperation] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ElasticPoolOperationListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ElasticPoolOperationListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_elastic_pool_request( resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_elastic_pool.metadata['url'], + template_url=self.list_by_elastic_pool.metadata["url"], headers=_headers, params=_params, ) @@ -169,17 +154,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_elastic_pool_request( - resource_group_name=resource_group_name, - server_name=server_name, - elastic_pool_name=elastic_pool_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -195,10 +170,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -208,8 +181,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_elastic_pool.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/operations"} # type: ignore + list_by_elastic_pool.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/operations"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_elastic_pools_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_elastic_pools_operations.py index 24e2c6c361f6a..a6898a4fe7643 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_elastic_pools_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_elastic_pools_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,21 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._elastic_pools_operations import build_create_or_update_request_initial, build_delete_request_initial, build_failover_request_initial, build_get_request, build_list_by_server_request, build_list_metric_definitions_request, build_list_metrics_request, build_update_request_initial -T = TypeVar('T') +from ...operations._elastic_pools_operations import ( + build_create_or_update_request, + build_delete_request, + build_failover_request, + build_get_request, + build_list_by_server_request, + build_list_metric_definitions_request, + build_list_metrics_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ElasticPoolsOperations: """ .. warning:: @@ -45,56 +62,47 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_metrics( - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - filter: str, - **kwargs: Any - ) -> AsyncIterable[_models.MetricListResult]: + self, resource_group_name: str, server_name: str, elastic_pool_name: str, filter: str, **kwargs: Any + ) -> AsyncIterable["_models.Metric"]: """Returns elastic pool metrics. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool. + :param elastic_pool_name: The name of the elastic pool. Required. :type elastic_pool_name: str :param filter: An OData filter expression that describes a subset of metrics to return. + Required. :type filter: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either MetricListResult or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.MetricListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Metric or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.Metric] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.MetricListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.MetricListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_metrics_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, - api_version=api_version, + subscription_id=self._config.subscription_id, filter=filter, - template_url=self.list_metrics.metadata['url'], + api_version=api_version, + template_url=self.list_metrics.metadata["url"], headers=_headers, params=_params, ) @@ -102,18 +110,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_metrics_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - elastic_pool_name=elastic_pool_name, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -129,10 +126,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -142,59 +137,47 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_metrics.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/metrics"} # type: ignore + list_metrics.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/metrics"} # type: ignore @distributed_trace def list_metric_definitions( - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.MetricDefinitionListResult]: + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any + ) -> AsyncIterable["_models.MetricDefinition"]: """Returns elastic pool metric definitions. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool. + :param elastic_pool_name: The name of the elastic pool. Required. :type elastic_pool_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either MetricDefinitionListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.MetricDefinitionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either MetricDefinition or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.MetricDefinition] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.MetricDefinitionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.MetricDefinitionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_metric_definitions_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_metric_definitions.metadata['url'], + template_url=self.list_metric_definitions.metadata["url"], headers=_headers, params=_params, ) @@ -202,17 +185,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_metric_definitions_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - elastic_pool_name=elastic_pool_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -228,10 +201,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -241,58 +212,47 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_metric_definitions.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/metricDefinitions"} # type: ignore + list_metric_definitions.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/metricDefinitions"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - skip: Optional[int] = None, - **kwargs: Any - ) -> AsyncIterable[_models.ElasticPoolListResult]: + self, resource_group_name: str, server_name: str, skip: Optional[int] = None, **kwargs: Any + ) -> AsyncIterable["_models.ElasticPool"]: """Gets all elastic pools in a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param skip: The number of elements in the collection to skip. Default value is None. - :type skip: long - :keyword api_version: Api Version. Default value is "2021-08-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :type skip: int :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ElasticPoolListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ElasticPoolListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ElasticPool or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ElasticPool] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ElasticPoolListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ElasticPoolListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, - api_version=api_version, skip=skip, - template_url=self.list_by_server.metadata['url'], + api_version=api_version, + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -300,17 +260,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - skip=skip, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -326,10 +276,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -339,56 +287,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any ) -> _models.ElasticPool: """Gets an elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool. + :param elastic_pool_name: The name of the elastic pool. Required. :type elastic_pool_name: str - :keyword api_version: Api Version. Default value is "2021-08-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ElasticPool, or the result of cls(response) + :return: ElasticPool or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ElasticPool - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ElasticPool] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ElasticPool] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -396,49 +332,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ElasticPool', pipeline_response) + deserialized = self._deserialize("ElasticPool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, elastic_pool_name: str, - parameters: _models.ElasticPool, + parameters: Union[_models.ElasticPool, IO], **kwargs: Any ) -> Optional[_models.ElasticPool]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ElasticPool]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ElasticPool]] - _json = self._serialize.body(parameters, 'ElasticPool') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ElasticPool") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, @@ -446,7 +384,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -454,10 +393,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -466,42 +404,82 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ElasticPool', pipeline_response) + deserialized = self._deserialize("ElasticPool", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ElasticPool', pipeline_response) + deserialized = self._deserialize("ElasticPool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, elastic_pool_name: str, parameters: _models.ElasticPool, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ElasticPool]: """Creates or updates an elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool. + :param elastic_pool_name: The name of the elastic pool. Required. :type elastic_pool_name: str - :param parameters: The elastic pool parameters. + :param parameters: The elastic pool parameters. Required. :type parameters: ~azure.mgmt.sql.models.ElasticPool - :keyword api_version: Api Version. Default value is "2021-08-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ElasticPool or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ElasticPool] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + elastic_pool_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ElasticPool]: + """Creates or updates an elastic pool. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param elastic_pool_name: The name of the elastic pool. Required. + :type elastic_pool_name: str + :param parameters: The elastic pool parameters. Required. + :type parameters: IO + :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 @@ -513,20 +491,54 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either ElasticPool or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ElasticPool] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + elastic_pool_name: str, + parameters: Union[_models.ElasticPool, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ElasticPool]: + """Creates or updates an elastic pool. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param elastic_pool_name: The name of the elastic pool. Required. + :type elastic_pool_name: str + :param parameters: The elastic pool parameters. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ElasticPool 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. + :return: An instance of AsyncLROPoller that returns either ElasticPool or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ElasticPool] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ElasticPool] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ElasticPool] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -535,66 +547,55 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ElasticPool', pipeline_response) + deserialized = self._deserialize("ElasticPool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -602,10 +603,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -615,29 +615,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes an elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool. + :param elastic_pool_name: The name of the elastic pool. Required. :type elastic_pool_name: str - :keyword api_version: Api Version. Default value is "2021-08-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -648,80 +640,77 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore async def _update_initial( self, resource_group_name: str, server_name: str, elastic_pool_name: str, - parameters: _models.ElasticPoolUpdate, + parameters: Union[_models.ElasticPoolUpdate, IO], **kwargs: Any ) -> Optional[_models.ElasticPool]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ElasticPool]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ElasticPool]] - _json = self._serialize.body(parameters, 'ElasticPoolUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ElasticPoolUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, @@ -729,7 +718,8 @@ async def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -737,10 +727,9 @@ async def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -749,39 +738,117 @@ async def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ElasticPool', pipeline_response) + deserialized = self._deserialize("ElasticPool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore - + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore - @distributed_trace_async + @overload async def begin_update( self, resource_group_name: str, server_name: str, elastic_pool_name: str, parameters: _models.ElasticPoolUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ElasticPool]: """Updates an elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool. + :param elastic_pool_name: The name of the elastic pool. Required. :type elastic_pool_name: str - :param parameters: The elastic pool update parameters. + :param parameters: The elastic pool update parameters. Required. :type parameters: ~azure.mgmt.sql.models.ElasticPoolUpdate - :keyword api_version: Api Version. Default value is "2021-08-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ElasticPool or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ElasticPool] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_update( + self, + resource_group_name: str, + server_name: str, + elastic_pool_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ElasticPool]: + """Updates an elastic pool. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param elastic_pool_name: The name of the elastic pool. Required. + :type elastic_pool_name: str + :param parameters: The elastic pool update parameters. Required. + :type parameters: IO + :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 ElasticPool or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ElasticPool] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_update( + self, + resource_group_name: str, + server_name: str, + elastic_pool_name: str, + parameters: Union[_models.ElasticPoolUpdate, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ElasticPool]: + """Updates an elastic pool. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param elastic_pool_name: The name of the elastic pool. Required. + :type elastic_pool_name: str + :param parameters: The elastic pool update parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ElasticPoolUpdate 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 @@ -793,20 +860,17 @@ async def begin_update( :return: An instance of AsyncLROPoller that returns either ElasticPool or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ElasticPool] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ElasticPool] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ElasticPool] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -815,66 +879,55 @@ async def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ElasticPool', pipeline_response) + deserialized = self._deserialize("ElasticPool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore async def _failover_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_failover_request_initial( + request = build_failover_request( resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._failover_initial.metadata['url'], + template_url=self._failover_initial.metadata["url"], headers=_headers, params=_params, ) @@ -882,10 +935,9 @@ async def _failover_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -895,29 +947,21 @@ async def _failover_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _failover_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/failover"} # type: ignore - + _failover_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/failover"} # type: ignore @distributed_trace_async - async def begin_failover( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any + async def begin_failover( + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Failovers an elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool to failover. + :param elastic_pool_name: The name of the elastic pool to failover. Required. :type elastic_pool_name: str - :keyword api_version: Api Version. Default value is "2021-08-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -928,53 +972,46 @@ async def begin_failover( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._failover_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_failover.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/failover"} # type: ignore + begin_failover.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/failover"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_encryption_protectors_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_encryption_protectors_operations.py index 40344bc4e6147..c792d09d6ad37 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_encryption_protectors_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_encryption_protectors_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._encryption_protectors_operations import build_create_or_update_request_initial, build_get_request, build_list_by_server_request, build_revalidate_request_initial -T = TypeVar('T') +from ...operations._encryption_protectors_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_server_request, + build_revalidate_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class EncryptionProtectorsOperations: """ .. warning:: @@ -45,50 +58,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.EncryptionProtectorListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.EncryptionProtector"]: """Gets a list of server encryption protectors. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either EncryptionProtectorListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.EncryptionProtectorListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either EncryptionProtector or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.EncryptionProtector] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.EncryptionProtectorListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.EncryptionProtectorListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -96,16 +99,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -121,10 +115,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -134,11 +126,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector"} # type: ignore @distributed_trace_async async def get( @@ -151,39 +141,34 @@ async def get( """Gets a server encryption protector. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param encryption_protector_name: The name of the encryption protector to be retrieved. + "current" Required. :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: EncryptionProtector, or the result of cls(response) + :return: EncryptionProtector or the result of cls(response) :rtype: ~azure.mgmt.sql.models.EncryptionProtector - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.EncryptionProtector] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.EncryptionProtector] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, encryption_protector_name=encryption_protector_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -191,49 +176,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('EncryptionProtector', pipeline_response) + deserialized = self._deserialize("EncryptionProtector", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], - parameters: _models.EncryptionProtector, + parameters: Union[_models.EncryptionProtector, IO], **kwargs: Any ) -> Optional[_models.EncryptionProtector]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.EncryptionProtector]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.EncryptionProtector]] - _json = self._serialize.body(parameters, 'EncryptionProtector') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "EncryptionProtector") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, encryption_protector_name=encryption_protector_name, @@ -241,7 +228,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -249,10 +237,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -261,39 +248,41 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('EncryptionProtector', pipeline_response) + deserialized = self._deserialize("EncryptionProtector", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], parameters: _models.EncryptionProtector, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.EncryptionProtector]: """Updates an existing encryption protector. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param encryption_protector_name: The name of the encryption protector to be updated. + :param encryption_protector_name: The name of the encryption protector to be updated. "current" + Required. :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName - :param parameters: The requested encryption protector resource state. + :param parameters: The requested encryption protector resource state. Required. :type parameters: ~azure.mgmt.sql.models.EncryptionProtector - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -305,20 +294,96 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either EncryptionProtector or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.EncryptionProtector] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.EncryptionProtector]: + """Updates an existing encryption protector. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param encryption_protector_name: The name of the encryption protector to be updated. "current" + Required. + :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName + :param parameters: The requested encryption protector resource state. Required. + :type parameters: IO + :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 EncryptionProtector or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.EncryptionProtector] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], + parameters: Union[_models.EncryptionProtector, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.EncryptionProtector]: + """Updates an existing encryption protector. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param encryption_protector_name: The name of the encryption protector to be updated. "current" + Required. + :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName + :param parameters: The requested encryption protector resource state. Is either a model type or + a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.EncryptionProtector 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. + :return: An instance of AsyncLROPoller that returns either EncryptionProtector or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.EncryptionProtector] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.EncryptionProtector] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.EncryptionProtector] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -327,39 +392,35 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('EncryptionProtector', pipeline_response) + deserialized = self._deserialize("EncryptionProtector", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore async def _revalidate_initial( # pylint: disable=inconsistent-return-statements self, @@ -368,25 +429,22 @@ async def _revalidate_initial( # pylint: disable=inconsistent-return-statements encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_revalidate_request_initial( + request = build_revalidate_request( resource_group_name=resource_group_name, server_name=server_name, encryption_protector_name=encryption_protector_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._revalidate_initial.metadata['url'], + template_url=self._revalidate_initial.metadata["url"], headers=_headers, params=_params, ) @@ -394,10 +452,9 @@ async def _revalidate_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -407,11 +464,10 @@ async def _revalidate_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _revalidate_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}/revalidate"} # type: ignore - + _revalidate_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}/revalidate"} # type: ignore @distributed_trace_async - async def begin_revalidate( # pylint: disable=inconsistent-return-statements + async def begin_revalidate( self, resource_group_name: str, server_name: str, @@ -421,15 +477,13 @@ async def begin_revalidate( # pylint: disable=inconsistent-return-statements """Revalidates an existing encryption protector. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param encryption_protector_name: The name of the encryption protector to be updated. + :param encryption_protector_name: The name of the encryption protector to be updated. "current" + Required. :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -440,53 +494,46 @@ async def begin_revalidate( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._revalidate_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, encryption_protector_name=encryption_protector_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_revalidate.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}/revalidate"} # type: ignore + begin_revalidate.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}/revalidate"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_endpoint_certificates_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_endpoint_certificates_operations.py index afdc394f3e337..d9b0542fc6849 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_endpoint_certificates_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_endpoint_certificates_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._endpoint_certificates_operations import build_get_request, build_list_by_instance_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class EndpointCertificatesOperations: """ .. warning:: @@ -43,50 +51,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.EndpointCertificateListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.EndpointCertificate"]: """List certificates used on endpoints on the target instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either EndpointCertificateListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.EndpointCertificateListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either EndpointCertificate or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.EndpointCertificate] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.EndpointCertificateListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.EndpointCertificateListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -94,16 +92,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -119,10 +108,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -132,56 +119,45 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/endpointCertificates"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/endpointCertificates"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - managed_instance_name: str, - endpoint_type: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, endpoint_type: str, **kwargs: Any ) -> _models.EndpointCertificate: """Gets a certificate used on the endpoint with the given id. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param endpoint_type: Type of the endpoint whose certificate the customer is looking for. + Required. :type endpoint_type: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: EndpointCertificate, or the result of cls(response) + :return: EndpointCertificate or the result of cls(response) :rtype: ~azure.mgmt.sql.models.EndpointCertificate - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.EndpointCertificate] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.EndpointCertificate] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, endpoint_type=endpoint_type, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -189,22 +165,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('EndpointCertificate', pipeline_response) + deserialized = self._deserialize("EndpointCertificate", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/endpointCertificates/{endpointType}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/endpointCertificates/{endpointType}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_extended_database_blob_auditing_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_extended_database_blob_auditing_policies_operations.py index d376683364ed8..5355c1a258a43 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_extended_database_blob_auditing_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_extended_database_blob_auditing_policies_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._extended_database_blob_auditing_policies_operations import build_create_or_update_request, build_get_request, build_list_by_database_request -T = TypeVar('T') +from ...operations._extended_database_blob_auditing_policies_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ExtendedDatabaseBlobAuditingPoliciesOperations: """ .. warning:: @@ -43,54 +55,45 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ExtendedDatabaseBlobAuditingPolicyListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ExtendedDatabaseBlobAuditingPolicy"]: """Lists extended auditing settings of a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ExtendedDatabaseBlobAuditingPolicyListResult or - the result of cls(response) + :return: An iterator like instance of either ExtendedDatabaseBlobAuditingPolicy or the result + of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ExtendedDatabaseBlobAuditingPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ExtendedDatabaseBlobAuditingPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ExtendedDatabaseBlobAuditingPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ExtendedDatabaseBlobAuditingPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -98,17 +101,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -124,10 +117,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -137,53 +128,41 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> _models.ExtendedDatabaseBlobAuditingPolicy: """Gets an extended database's blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is "default". Note that overriding this default value may result in unsupported behavior. :paramtype blob_auditing_policy_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ExtendedDatabaseBlobAuditingPolicy, or the result of cls(response) + :return: ExtendedDatabaseBlobAuditingPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ExtendedDatabaseBlobAuditingPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ExtendedDatabaseBlobAuditingPolicy] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ExtendedDatabaseBlobAuditingPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -191,7 +170,7 @@ async def get( subscription_id=self._config.subscription_id, blob_auditing_policy_name=blob_auditing_policy_name, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -199,71 +178,142 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ExtendedDatabaseBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ExtendedDatabaseBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.ExtendedDatabaseBlobAuditingPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.ExtendedDatabaseBlobAuditingPolicy: """Creates or updates an extended database's blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The extended database blob auditing policy. + :param parameters: The extended database blob auditing policy. Required. :type parameters: ~azure.mgmt.sql.models.ExtendedDatabaseBlobAuditingPolicy + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is "default". Note that overriding this default value may result in unsupported behavior. :paramtype blob_auditing_policy_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ExtendedDatabaseBlobAuditingPolicy, or the result of cls(response) + :return: ExtendedDatabaseBlobAuditingPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ExtendedDatabaseBlobAuditingPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.ExtendedDatabaseBlobAuditingPolicy: + """Creates or updates an extended database's blob auditing policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The extended database blob auditing policy. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is + "default". Note that overriding this default value may result in unsupported behavior. + :paramtype blob_auditing_policy_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ExtendedDatabaseBlobAuditingPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ExtendedDatabaseBlobAuditingPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.ExtendedDatabaseBlobAuditingPolicy, IO], + **kwargs: Any + ) -> _models.ExtendedDatabaseBlobAuditingPolicy: + """Creates or updates an extended database's blob auditing policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The extended database blob auditing policy. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.ExtendedDatabaseBlobAuditingPolicy or IO + :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is + "default". Note that overriding this default value may result in unsupported behavior. + :paramtype blob_auditing_policy_name: str + :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 + :return: ExtendedDatabaseBlobAuditingPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ExtendedDatabaseBlobAuditingPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ExtendedDatabaseBlobAuditingPolicy] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ExtendedDatabaseBlobAuditingPolicy] - _json = self._serialize.body(parameters, 'ExtendedDatabaseBlobAuditingPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ExtendedDatabaseBlobAuditingPolicy") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -274,7 +324,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -282,10 +333,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -293,15 +343,14 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('ExtendedDatabaseBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ExtendedDatabaseBlobAuditingPolicy", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ExtendedDatabaseBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ExtendedDatabaseBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_extended_server_blob_auditing_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_extended_server_blob_auditing_policies_operations.py index f4aed482d61e4..8df559fa9d95c 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_extended_server_blob_auditing_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_extended_server_blob_auditing_policies_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._extended_server_blob_auditing_policies_operations import build_create_or_update_request_initial, build_get_request, build_list_by_server_request -T = TypeVar('T') +from ...operations._extended_server_blob_auditing_policies_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_server_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ExtendedServerBlobAuditingPoliciesOperations: """ .. warning:: @@ -45,50 +57,42 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ExtendedServerBlobAuditingPolicyListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ExtendedServerBlobAuditingPolicy"]: """Lists extended auditing settings of a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ExtendedServerBlobAuditingPolicyListResult or the - result of cls(response) + :return: An iterator like instance of either ExtendedServerBlobAuditingPolicy or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ExtendedServerBlobAuditingPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ExtendedServerBlobAuditingPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ExtendedServerBlobAuditingPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ExtendedServerBlobAuditingPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -96,16 +100,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -121,10 +116,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -134,57 +127,46 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, **kwargs: Any ) -> _models.ExtendedServerBlobAuditingPolicy: """Gets an extended server's blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is "default". Note that overriding this default value may result in unsupported behavior. :paramtype blob_auditing_policy_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ExtendedServerBlobAuditingPolicy, or the result of cls(response) + :return: ExtendedServerBlobAuditingPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ExtendedServerBlobAuditingPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ExtendedServerBlobAuditingPolicy] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ExtendedServerBlobAuditingPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, blob_auditing_policy_name=blob_auditing_policy_name, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -192,49 +174,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ExtendedServerBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ExtendedServerBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, - parameters: _models.ExtendedServerBlobAuditingPolicy, + parameters: Union[_models.ExtendedServerBlobAuditingPolicy, IO], **kwargs: Any ) -> Optional[_models.ExtendedServerBlobAuditingPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ExtendedServerBlobAuditingPolicy]] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ExtendedServerBlobAuditingPolicy]] - _json = self._serialize.body(parameters, 'ExtendedServerBlobAuditingPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ExtendedServerBlobAuditingPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, @@ -242,7 +226,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -250,10 +235,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -262,39 +246,40 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ExtendedServerBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ExtendedServerBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, parameters: _models.ExtendedServerBlobAuditingPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ExtendedServerBlobAuditingPolicy]: """Creates or updates an extended server's blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param parameters: Properties of extended blob auditing policy. + :param parameters: Properties of extended blob auditing policy. Required. :type parameters: ~azure.mgmt.sql.models.ExtendedServerBlobAuditingPolicy + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is "default". Note that overriding this default value may result in unsupported behavior. :paramtype blob_auditing_policy_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -307,21 +292,97 @@ async def begin_create_or_update( the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ExtendedServerBlobAuditingPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ExtendedServerBlobAuditingPolicy]: + """Creates or updates an extended server's blob auditing policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: Properties of extended blob auditing policy. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is + "default". Note that overriding this default value may result in unsupported behavior. + :paramtype blob_auditing_policy_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 ExtendedServerBlobAuditingPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ExtendedServerBlobAuditingPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + parameters: Union[_models.ExtendedServerBlobAuditingPolicy, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ExtendedServerBlobAuditingPolicy]: + """Creates or updates an extended server's blob auditing policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: Properties of extended blob auditing policy. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.ExtendedServerBlobAuditingPolicy or IO + :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is + "default". Note that overriding this default value may result in unsupported behavior. + :paramtype blob_auditing_policy_name: str + :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. + :return: An instance of AsyncLROPoller that returns either ExtendedServerBlobAuditingPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ExtendedServerBlobAuditingPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ExtendedServerBlobAuditingPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ExtendedServerBlobAuditingPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -330,36 +391,32 @@ async def begin_create_or_update( blob_auditing_policy_name=blob_auditing_policy_name, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ExtendedServerBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ExtendedServerBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_failover_groups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_failover_groups_operations.py index 7448e383cf3c4..56d9ec6bd8dfb 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_failover_groups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_failover_groups_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,20 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._failover_groups_operations import build_create_or_update_request_initial, build_delete_request_initial, build_failover_request_initial, build_force_failover_allow_data_loss_request_initial, build_get_request, build_list_by_server_request, build_update_request_initial -T = TypeVar('T') +from ...operations._failover_groups_operations import ( + build_create_or_update_request, + build_delete_request, + build_failover_request, + build_force_failover_allow_data_loss_request, + build_get_request, + build_list_by_server_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class FailoverGroupsOperations: """ .. warning:: @@ -45,51 +61,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, failover_group_name: str, **kwargs: Any ) -> _models.FailoverGroup: """Gets a failover group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server containing the failover group. + :param server_name: The name of the server containing the failover group. Required. :type server_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: FailoverGroup, or the result of cls(response) + :return: FailoverGroup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.FailoverGroup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.FailoverGroup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.FailoverGroup] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,49 +102,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, failover_group_name: str, - parameters: _models.FailoverGroup, + parameters: Union[_models.FailoverGroup, IO], **kwargs: Any ) -> Optional[_models.FailoverGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.FailoverGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.FailoverGroup]] - _json = self._serialize.body(parameters, 'FailoverGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "FailoverGroup") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, @@ -147,7 +154,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -155,10 +163,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -167,42 +174,120 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, failover_group_name: str, parameters: _models.FailoverGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.FailoverGroup]: """Creates or updates a failover group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server containing the failover group. + :param server_name: The name of the server containing the failover group. Required. :type server_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :param parameters: The failover group parameters. + :param parameters: The failover group parameters. Required. :type parameters: ~azure.mgmt.sql.models.FailoverGroup - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 FailoverGroup or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.FailoverGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + failover_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.FailoverGroup]: + """Creates or updates a failover group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server containing the failover group. Required. + :type server_name: str + :param failover_group_name: The name of the failover group. Required. + :type failover_group_name: str + :param parameters: The failover group parameters. Required. + :type parameters: IO + :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 FailoverGroup or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.FailoverGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + failover_group_name: str, + parameters: Union[_models.FailoverGroup, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.FailoverGroup]: + """Creates or updates a failover group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server containing the failover group. Required. + :type server_name: str + :param failover_group_name: The name of the failover group. Required. + :type failover_group_name: str + :param parameters: The failover group parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.FailoverGroup 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 @@ -214,20 +299,17 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either FailoverGroup or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.FailoverGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.FailoverGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.FailoverGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -236,66 +318,55 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, failover_group_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -303,10 +374,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -316,29 +386,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - failover_group_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, server_name: str, failover_group_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes a failover group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server containing the failover group. + :param server_name: The name of the server containing the failover group. Required. :type server_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -349,80 +411,77 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore async def _update_initial( self, resource_group_name: str, server_name: str, failover_group_name: str, - parameters: _models.FailoverGroupUpdate, + parameters: Union[_models.FailoverGroupUpdate, IO], **kwargs: Any ) -> Optional[_models.FailoverGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.FailoverGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.FailoverGroup]] - _json = self._serialize.body(parameters, 'FailoverGroupUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "FailoverGroupUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, @@ -430,7 +489,8 @@ async def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -438,10 +498,9 @@ async def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -450,39 +509,117 @@ async def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_update( self, resource_group_name: str, server_name: str, failover_group_name: str, parameters: _models.FailoverGroupUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.FailoverGroup]: """Updates a failover group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server containing the failover group. + :param server_name: The name of the server containing the failover group. Required. :type server_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :param parameters: The failover group parameters. + :param parameters: The failover group parameters. Required. :type parameters: ~azure.mgmt.sql.models.FailoverGroupUpdate - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 FailoverGroup or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.FailoverGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_update( + self, + resource_group_name: str, + server_name: str, + failover_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.FailoverGroup]: + """Updates a failover group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server containing the failover group. Required. + :type server_name: str + :param failover_group_name: The name of the failover group. Required. + :type failover_group_name: str + :param parameters: The failover group parameters. Required. + :type parameters: IO + :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 FailoverGroup or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.FailoverGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_update( + self, + resource_group_name: str, + server_name: str, + failover_group_name: str, + parameters: Union[_models.FailoverGroupUpdate, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.FailoverGroup]: + """Updates a failover group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server containing the failover group. Required. + :type server_name: str + :param failover_group_name: The name of the failover group. Required. + :type failover_group_name: str + :param parameters: The failover group parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.FailoverGroupUpdate 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 @@ -494,20 +631,17 @@ async def begin_update( :return: An instance of AsyncLROPoller that returns either FailoverGroup or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.FailoverGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.FailoverGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.FailoverGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -516,82 +650,70 @@ async def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.FailoverGroupListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.FailoverGroup"]: """Lists the failover groups in a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server containing the failover group. + :param server_name: The name of the server containing the failover group. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either FailoverGroupListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.FailoverGroupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either FailoverGroup or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.FailoverGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.FailoverGroupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.FailoverGroupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -599,16 +721,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -624,10 +737,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -637,38 +748,29 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups"} # type: ignore async def _failover_initial( - self, - resource_group_name: str, - server_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, failover_group_name: str, **kwargs: Any ) -> Optional[_models.FailoverGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.FailoverGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.FailoverGroup]] - - request = build_failover_request_initial( + request = build_failover_request( resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._failover_initial.metadata['url'], + template_url=self._failover_initial.metadata["url"], headers=_headers, params=_params, ) @@ -676,10 +778,9 @@ async def _failover_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -688,36 +789,28 @@ async def _failover_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _failover_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/failover"} # type: ignore - + _failover_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/failover"} # type: ignore @distributed_trace_async async def begin_failover( - self, - resource_group_name: str, - server_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, failover_group_name: str, **kwargs: Any ) -> AsyncLROPoller[_models.FailoverGroup]: """Fails over from the current primary server to this server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server containing the failover group. + :param server_name: The name of the server containing the failover group. Required. :type server_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -729,85 +822,71 @@ async def begin_failover( :return: An instance of AsyncLROPoller that returns either FailoverGroup or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.FailoverGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.FailoverGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.FailoverGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._failover_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_failover.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/failover"} # type: ignore + begin_failover.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/failover"} # type: ignore async def _force_failover_allow_data_loss_initial( - self, - resource_group_name: str, - server_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, failover_group_name: str, **kwargs: Any ) -> Optional[_models.FailoverGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.FailoverGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.FailoverGroup]] - - request = build_force_failover_allow_data_loss_request_initial( + request = build_force_failover_allow_data_loss_request( resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._force_failover_allow_data_loss_initial.metadata['url'], + template_url=self._force_failover_allow_data_loss_initial.metadata["url"], headers=_headers, params=_params, ) @@ -815,10 +894,9 @@ async def _force_failover_allow_data_loss_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -827,37 +905,29 @@ async def _force_failover_allow_data_loss_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _force_failover_allow_data_loss_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss"} # type: ignore - + _force_failover_allow_data_loss_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss"} # type: ignore @distributed_trace_async async def begin_force_failover_allow_data_loss( - self, - resource_group_name: str, - server_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, failover_group_name: str, **kwargs: Any ) -> AsyncLROPoller[_models.FailoverGroup]: """Fails over from the current primary server to this server. This operation might result in data loss. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server containing the failover group. + :param server_name: The name of the server containing the failover group. Required. :type server_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -869,55 +939,48 @@ async def begin_force_failover_allow_data_loss( :return: An instance of AsyncLROPoller that returns either FailoverGroup or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.FailoverGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.FailoverGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.FailoverGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._force_failover_allow_data_loss_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_force_failover_allow_data_loss.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss"} # type: ignore + begin_force_failover_allow_data_loss.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_firewall_rules_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_firewall_rules_operations.py index 974a266999116..d2677abf28a5e 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_firewall_rules_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_firewall_rules_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,18 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._firewall_rules_operations import build_create_or_update_request, build_delete_request, build_get_request, build_list_by_server_request, build_replace_request -T = TypeVar('T') +from ...operations._firewall_rules_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_server_request, + build_replace_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class FirewallRulesOperations: """ .. warning:: @@ -43,51 +57,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - firewall_rule_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, firewall_rule_name: str, **kwargs: Any ) -> _models.FirewallRule: """Gets a firewall rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param firewall_rule_name: The name of the firewall rule. + :param firewall_rule_name: The name of the firewall rule. Required. :type firewall_rule_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: FirewallRule, or the result of cls(response) + :return: FirewallRule or the result of cls(response) :rtype: ~azure.mgmt.sql.models.FirewallRule - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.FirewallRule] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.FirewallRule] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, firewall_rule_name=firewall_rule_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -95,67 +98,132 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('FirewallRule', pipeline_response) + deserialized = self._deserialize("FirewallRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}"} # type: ignore - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, server_name: str, firewall_rule_name: str, parameters: _models.FirewallRule, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.FirewallRule: """Creates or updates a firewall rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param firewall_rule_name: The name of the firewall rule. + :param firewall_rule_name: The name of the firewall rule. Required. :type firewall_rule_name: str - :param parameters: The required parameters for creating or updating a firewall rule. + :param parameters: The required parameters for creating or updating a firewall rule. Required. :type parameters: ~azure.mgmt.sql.models.FirewallRule - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: FirewallRule or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.FirewallRule + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + firewall_rule_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.FirewallRule: + """Creates or updates a firewall rule. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param firewall_rule_name: The name of the firewall rule. Required. + :type firewall_rule_name: str + :param parameters: The required parameters for creating or updating a firewall rule. Required. + :type parameters: IO + :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: FirewallRule, or the result of cls(response) + :return: FirewallRule or the result of cls(response) :rtype: ~azure.mgmt.sql.models.FirewallRule - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + firewall_rule_name: str, + parameters: Union[_models.FirewallRule, IO], + **kwargs: Any + ) -> _models.FirewallRule: + """Creates or updates a firewall rule. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param firewall_rule_name: The name of the firewall rule. Required. + :type firewall_rule_name: str + :param parameters: The required parameters for creating or updating a firewall rule. Is either + a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.FirewallRule 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 + :return: FirewallRule or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.FirewallRule + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.FirewallRule] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.FirewallRule] - _json = self._serialize.body(parameters, 'FirewallRule') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "FirewallRule") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -165,7 +233,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -173,10 +242,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -184,63 +252,52 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('FirewallRule', pipeline_response) + deserialized = self._deserialize("FirewallRule", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('FirewallRule', pipeline_response) + deserialized = self._deserialize("FirewallRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}"} # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - firewall_rule_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, firewall_rule_name: str, **kwargs: Any ) -> None: """Deletes a firewall rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param firewall_rule_name: The name of the firewall rule. + :param firewall_rule_name: The name of the firewall rule. Required. :type firewall_rule_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, firewall_rule_name=firewall_rule_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -248,10 +305,9 @@ async def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 204]: @@ -261,51 +317,42 @@ async def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.FirewallRuleListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.FirewallRule"]: """Gets a list of firewall rules. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either FirewallRuleListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.FirewallRuleListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either FirewallRule or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.FirewallRule] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.FirewallRuleListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.FirewallRuleListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -313,16 +360,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -338,10 +376,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -351,50 +387,104 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules"} # type: ignore - @distributed_trace_async + @overload async def replace( self, resource_group_name: str, server_name: str, parameters: _models.FirewallRuleList, + *, + content_type: str = "application/json", **kwargs: Any ) -> Optional[_models.FirewallRule]: """Replaces all firewall rules on the server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.FirewallRuleList - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: FirewallRule, or the result of cls(response) + :return: FirewallRule or None or the result of cls(response) :rtype: ~azure.mgmt.sql.models.FirewallRule or None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def replace( + self, + resource_group_name: str, + server_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> Optional[_models.FirewallRule]: + """Replaces all firewall rules on the server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: Required. + :type parameters: IO + :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: FirewallRule or None or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.FirewallRule or None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def replace( + self, resource_group_name: str, server_name: str, parameters: Union[_models.FirewallRuleList, IO], **kwargs: Any + ) -> Optional[_models.FirewallRule]: + """Replaces all firewall rules on the server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.FirewallRuleList 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 + :return: FirewallRule or None or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.FirewallRule or None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.FirewallRule]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.FirewallRule]] - _json = self._serialize.body(parameters, 'FirewallRuleList') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "FirewallRuleList") request = build_replace_request( resource_group_name=resource_group_name, @@ -403,7 +493,8 @@ async def replace( api_version=api_version, content_type=content_type, json=_json, - template_url=self.replace.metadata['url'], + content=_content, + template_url=self.replace.metadata["url"], headers=_headers, params=_params, ) @@ -411,10 +502,9 @@ async def replace( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -423,12 +513,11 @@ async def replace( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('FirewallRule', pipeline_response) + deserialized = self._deserialize("FirewallRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - replace.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules"} # type: ignore - + replace.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_geo_backup_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_geo_backup_policies_operations.py index 916c33e844d28..090fb0820f4bd 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_geo_backup_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_geo_backup_policies_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._geo_backup_policies_operations import build_create_or_update_request, build_get_request, build_list_by_database_request -T = TypeVar('T') +from ...operations._geo_backup_policies_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class GeoBackupPoliciesOperations: """ .. warning:: @@ -43,8 +55,7 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, @@ -52,53 +63,129 @@ async def create_or_update( database_name: str, geo_backup_policy_name: Union[str, "_models.GeoBackupPolicyName"], parameters: _models.GeoBackupPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.GeoBackupPolicy: """Updates a database geo backup policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param geo_backup_policy_name: The name of the geo backup policy. + :param geo_backup_policy_name: The name of the geo backup policy. "Default" Required. :type geo_backup_policy_name: str or ~azure.mgmt.sql.models.GeoBackupPolicyName :param parameters: The required parameters for creating or updating the geo backup policy. + Required. :type parameters: ~azure.mgmt.sql.models.GeoBackupPolicy - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str + :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: GeoBackupPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.GeoBackupPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + geo_backup_policy_name: Union[str, "_models.GeoBackupPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.GeoBackupPolicy: + """Updates a database geo backup policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param geo_backup_policy_name: The name of the geo backup policy. "Default" Required. + :type geo_backup_policy_name: str or ~azure.mgmt.sql.models.GeoBackupPolicyName + :param parameters: The required parameters for creating or updating the geo backup policy. + Required. + :type parameters: IO + :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: GeoBackupPolicy, or the result of cls(response) + :return: GeoBackupPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.GeoBackupPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + geo_backup_policy_name: Union[str, "_models.GeoBackupPolicyName"], + parameters: Union[_models.GeoBackupPolicy, IO], + **kwargs: Any + ) -> _models.GeoBackupPolicy: + """Updates a database geo backup policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param geo_backup_policy_name: The name of the geo backup policy. "Default" Required. + :type geo_backup_policy_name: str or ~azure.mgmt.sql.models.GeoBackupPolicyName + :param parameters: The required parameters for creating or updating the geo backup policy. Is + either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.GeoBackupPolicy 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 + :return: GeoBackupPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.GeoBackupPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.GeoBackupPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.GeoBackupPolicy] - _json = self._serialize.body(parameters, 'GeoBackupPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "GeoBackupPolicy") request = build_create_or_update_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, geo_backup_policy_name=geo_backup_policy_name, + subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -106,10 +193,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -117,18 +203,17 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('GeoBackupPolicy', pipeline_response) + deserialized = self._deserialize("GeoBackupPolicy", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('GeoBackupPolicy', pipeline_response) + deserialized = self._deserialize("GeoBackupPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies/{geoBackupPolicyName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies/{geoBackupPolicyName}"} # type: ignore @distributed_trace_async async def get( @@ -142,42 +227,36 @@ async def get( """Gets a geo backup policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param geo_backup_policy_name: The name of the geo backup policy. + :param geo_backup_policy_name: The name of the geo backup policy. "Default" Required. :type geo_backup_policy_name: str or ~azure.mgmt.sql.models.GeoBackupPolicyName - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: GeoBackupPolicy, or the result of cls(response) + :return: GeoBackupPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.GeoBackupPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.GeoBackupPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.GeoBackupPolicy] - request = build_get_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, geo_backup_policy_name=geo_backup_policy_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -185,73 +264,61 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('GeoBackupPolicy', pipeline_response) + deserialized = self._deserialize("GeoBackupPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies/{geoBackupPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies/{geoBackupPolicyName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.GeoBackupPolicyListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.GeoBackupPolicy"]: """Returns a list of geo backup policies. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either GeoBackupPolicyListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.GeoBackupPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either GeoBackupPolicy or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.GeoBackupPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.GeoBackupPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.GeoBackupPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -259,17 +326,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -285,10 +342,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -298,8 +353,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_instance_failover_groups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_instance_failover_groups_operations.py index 3afbbe71d6117..8f15a52eb0e16 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_instance_failover_groups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_instance_failover_groups_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,19 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._instance_failover_groups_operations import build_create_or_update_request_initial, build_delete_request_initial, build_failover_request_initial, build_force_failover_allow_data_loss_request_initial, build_get_request, build_list_by_location_request -T = TypeVar('T') +from ...operations._instance_failover_groups_operations import ( + build_create_or_update_request, + build_delete_request, + build_failover_request, + build_force_failover_allow_data_loss_request, + build_get_request, + build_list_by_location_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class InstanceFailoverGroupsOperations: """ .. warning:: @@ -45,51 +60,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - resource_group_name: str, - location_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, location_name: str, failover_group_name: str, **kwargs: Any ) -> _models.InstanceFailoverGroup: """Gets a failover group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: InstanceFailoverGroup, or the result of cls(response) + :return: InstanceFailoverGroup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.InstanceFailoverGroup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstanceFailoverGroup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstanceFailoverGroup] - request = build_get_request( resource_group_name=resource_group_name, location_name=location_name, failover_group_name=failover_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,49 +101,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('InstanceFailoverGroup', pipeline_response) + deserialized = self._deserialize("InstanceFailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, location_name: str, failover_group_name: str, - parameters: _models.InstanceFailoverGroup, + parameters: Union[_models.InstanceFailoverGroup, IO], **kwargs: Any ) -> Optional[_models.InstanceFailoverGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.InstanceFailoverGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.InstanceFailoverGroup]] - _json = self._serialize.body(parameters, 'InstanceFailoverGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "InstanceFailoverGroup") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, location_name=location_name, failover_group_name=failover_group_name, @@ -147,7 +153,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -155,10 +162,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -167,42 +173,120 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('InstanceFailoverGroup', pipeline_response) + deserialized = self._deserialize("InstanceFailoverGroup", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('InstanceFailoverGroup', pipeline_response) + deserialized = self._deserialize("InstanceFailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, location_name: str, failover_group_name: str, parameters: _models.InstanceFailoverGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.InstanceFailoverGroup]: """Creates or updates a failover group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :param parameters: The failover group parameters. + :param parameters: The failover group parameters. Required. :type parameters: ~azure.mgmt.sql.models.InstanceFailoverGroup - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 InstanceFailoverGroup or the result + of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.InstanceFailoverGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + location_name: str, + failover_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.InstanceFailoverGroup]: + """Creates or updates a failover group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param location_name: The name of the region where the resource is located. Required. + :type location_name: str + :param failover_group_name: The name of the failover group. Required. + :type failover_group_name: str + :param parameters: The failover group parameters. Required. + :type parameters: IO + :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 InstanceFailoverGroup or the result + of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.InstanceFailoverGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + location_name: str, + failover_group_name: str, + parameters: Union[_models.InstanceFailoverGroup, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.InstanceFailoverGroup]: + """Creates or updates a failover group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param location_name: The name of the region where the resource is located. Required. + :type location_name: str + :param failover_group_name: The name of the failover group. Required. + :type failover_group_name: str + :param parameters: The failover group parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.InstanceFailoverGroup 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 @@ -214,20 +298,17 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either InstanceFailoverGroup or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.InstanceFailoverGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstanceFailoverGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstanceFailoverGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -236,66 +317,55 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('InstanceFailoverGroup', pipeline_response) + deserialized = self._deserialize("InstanceFailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - location_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, location_name: str, failover_group_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, location_name=location_name, failover_group_name=failover_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -303,10 +373,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -316,29 +385,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - location_name: str, - failover_group_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, location_name: str, failover_group_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes a failover group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -349,100 +410,85 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, location_name=location_name, failover_group_name=failover_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore @distributed_trace def list_by_location( - self, - resource_group_name: str, - location_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.InstanceFailoverGroupListResult]: + self, resource_group_name: str, location_name: str, **kwargs: Any + ) -> AsyncIterable["_models.InstanceFailoverGroup"]: """Lists the failover groups in a location. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either InstanceFailoverGroupListResult or the result of + :return: An iterator like instance of either InstanceFailoverGroup or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.InstanceFailoverGroupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.InstanceFailoverGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstanceFailoverGroupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstanceFailoverGroupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_location_request( resource_group_name=resource_group_name, location_name=location_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_location.metadata['url'], + template_url=self.list_by_location.metadata["url"], headers=_headers, params=_params, ) @@ -450,16 +496,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_location_request( - resource_group_name=resource_group_name, - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -475,10 +512,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -488,38 +523,29 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups"} # type: ignore + list_by_location.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups"} # type: ignore async def _failover_initial( - self, - resource_group_name: str, - location_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, location_name: str, failover_group_name: str, **kwargs: Any ) -> Optional[_models.InstanceFailoverGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.InstanceFailoverGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.InstanceFailoverGroup]] - - request = build_failover_request_initial( + request = build_failover_request( resource_group_name=resource_group_name, location_name=location_name, failover_group_name=failover_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._failover_initial.metadata['url'], + template_url=self._failover_initial.metadata["url"], headers=_headers, params=_params, ) @@ -527,10 +553,9 @@ async def _failover_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -539,36 +564,28 @@ async def _failover_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('InstanceFailoverGroup', pipeline_response) + deserialized = self._deserialize("InstanceFailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _failover_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/failover"} # type: ignore - + _failover_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/failover"} # type: ignore @distributed_trace_async async def begin_failover( - self, - resource_group_name: str, - location_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, location_name: str, failover_group_name: str, **kwargs: Any ) -> AsyncLROPoller[_models.InstanceFailoverGroup]: """Fails over from the current primary managed instance to this managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -580,85 +597,71 @@ async def begin_failover( :return: An instance of AsyncLROPoller that returns either InstanceFailoverGroup or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.InstanceFailoverGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstanceFailoverGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstanceFailoverGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._failover_initial( # type: ignore resource_group_name=resource_group_name, location_name=location_name, failover_group_name=failover_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('InstanceFailoverGroup', pipeline_response) + deserialized = self._deserialize("InstanceFailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_failover.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/failover"} # type: ignore + begin_failover.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/failover"} # type: ignore async def _force_failover_allow_data_loss_initial( - self, - resource_group_name: str, - location_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, location_name: str, failover_group_name: str, **kwargs: Any ) -> Optional[_models.InstanceFailoverGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.InstanceFailoverGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.InstanceFailoverGroup]] - - request = build_force_failover_allow_data_loss_request_initial( + request = build_force_failover_allow_data_loss_request( resource_group_name=resource_group_name, location_name=location_name, failover_group_name=failover_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._force_failover_allow_data_loss_initial.metadata['url'], + template_url=self._force_failover_allow_data_loss_initial.metadata["url"], headers=_headers, params=_params, ) @@ -666,10 +669,9 @@ async def _force_failover_allow_data_loss_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -678,37 +680,29 @@ async def _force_failover_allow_data_loss_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('InstanceFailoverGroup', pipeline_response) + deserialized = self._deserialize("InstanceFailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _force_failover_allow_data_loss_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss"} # type: ignore - + _force_failover_allow_data_loss_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss"} # type: ignore @distributed_trace_async async def begin_force_failover_allow_data_loss( - self, - resource_group_name: str, - location_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, location_name: str, failover_group_name: str, **kwargs: Any ) -> AsyncLROPoller[_models.InstanceFailoverGroup]: """Fails over from the current primary managed instance to this managed instance. This operation might result in data loss. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -720,55 +714,48 @@ async def begin_force_failover_allow_data_loss( :return: An instance of AsyncLROPoller that returns either InstanceFailoverGroup or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.InstanceFailoverGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstanceFailoverGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstanceFailoverGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._force_failover_allow_data_loss_initial( # type: ignore resource_group_name=resource_group_name, location_name=location_name, failover_group_name=failover_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('InstanceFailoverGroup', pipeline_response) + deserialized = self._deserialize("InstanceFailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_force_failover_allow_data_loss.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss"} # type: ignore + begin_force_failover_allow_data_loss.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_instance_pools_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_instance_pools_operations.py index 303acd6c61e6a..74bf0d7d6b0c4 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_instance_pools_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_instance_pools_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,19 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._instance_pools_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_resource_group_request, build_list_request, build_update_request_initial -T = TypeVar('T') +from ...operations._instance_pools_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_resource_group_request, + build_list_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class InstancePoolsOperations: """ .. warning:: @@ -45,47 +60,35 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async - async def get( - self, - resource_group_name: str, - instance_pool_name: str, - **kwargs: Any - ) -> _models.InstancePool: + async def get(self, resource_group_name: str, instance_pool_name: str, **kwargs: Any) -> _models.InstancePool: """Gets an instance pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param instance_pool_name: The name of the instance pool to be retrieved. + :param instance_pool_name: The name of the instance pool to be retrieved. Required. :type instance_pool_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: InstancePool, or the result of cls(response) + :return: InstancePool or the result of cls(response) :rtype: ~azure.mgmt.sql.models.InstancePool - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstancePool] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstancePool] - request = build_get_request( resource_group_name=resource_group_name, instance_pool_name=instance_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -93,55 +96,58 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('InstancePool', pipeline_response) + deserialized = self._deserialize("InstancePool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, instance_pool_name: str, - parameters: _models.InstancePool, + parameters: Union[_models.InstancePool, IO], **kwargs: Any ) -> Optional[_models.InstancePool]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.InstancePool]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.InstancePool]] - _json = self._serialize.body(parameters, 'InstancePool') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "InstancePool") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, instance_pool_name=instance_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -149,10 +155,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -161,39 +166,40 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('InstancePool', pipeline_response) + deserialized = self._deserialize("InstancePool", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('InstancePool', pipeline_response) + deserialized = self._deserialize("InstancePool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, instance_pool_name: str, parameters: _models.InstancePool, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.InstancePool]: """Creates or updates an instance pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param instance_pool_name: The name of the instance pool to be created or updated. + :param instance_pool_name: The name of the instance pool to be created or updated. Required. :type instance_pool_name: str - :param parameters: The requested instance pool resource state. + :param parameters: The requested instance pool resource state. Required. :type parameters: ~azure.mgmt.sql.models.InstancePool - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -205,20 +211,88 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either InstancePool or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.InstancePool] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + instance_pool_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.InstancePool]: + """Creates or updates an instance pool. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param instance_pool_name: The name of the instance pool to be created or updated. Required. + :type instance_pool_name: str + :param parameters: The requested instance pool resource state. Required. + :type parameters: IO + :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 InstancePool or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.InstancePool] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + instance_pool_name: str, + parameters: Union[_models.InstancePool, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.InstancePool]: + """Creates or updates an instance pool. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param instance_pool_name: The name of the instance pool to be created or updated. Required. + :type instance_pool_name: str + :param parameters: The requested instance pool resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.InstancePool 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. + :return: An instance of AsyncLROPoller that returns either InstancePool or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.InstancePool] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstancePool] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstancePool] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -226,64 +300,54 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('InstancePool', pipeline_response) + deserialized = self._deserialize("InstancePool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/instancePools/{instancePoolName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - instance_pool_name: str, - **kwargs: Any + self, resource_group_name: str, instance_pool_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, instance_pool_name=instance_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -291,10 +355,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -304,26 +367,19 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - instance_pool_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, instance_pool_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes an instance pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param instance_pool_name: The name of the instance pool to be deleted. + :param instance_pool_name: The name of the instance pool to be deleted. Required. :type instance_pool_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -334,85 +390,83 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, instance_pool_name=instance_pool_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/instancePools/{instancePoolName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore async def _update_initial( self, resource_group_name: str, instance_pool_name: str, - parameters: _models.InstancePoolUpdate, + parameters: Union[_models.InstancePoolUpdate, IO], **kwargs: Any ) -> Optional[_models.InstancePool]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.InstancePool]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.InstancePool]] - _json = self._serialize.body(parameters, 'InstancePoolUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "InstancePoolUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, instance_pool_name=instance_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -420,10 +474,9 @@ async def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -432,36 +485,37 @@ async def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('InstancePool', pipeline_response) + deserialized = self._deserialize("InstancePool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore - + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore - @distributed_trace_async + @overload async def begin_update( self, resource_group_name: str, instance_pool_name: str, parameters: _models.InstancePoolUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.InstancePool]: """Updates an instance pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param instance_pool_name: The name of the instance pool to be updated. + :param instance_pool_name: The name of the instance pool to be updated. Required. :type instance_pool_name: str - :param parameters: The requested instance pool resource state. + :param parameters: The requested instance pool resource state. Required. :type parameters: ~azure.mgmt.sql.models.InstancePoolUpdate - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -473,20 +527,88 @@ async def begin_update( :return: An instance of AsyncLROPoller that returns either InstancePool or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.InstancePool] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_update( + self, + resource_group_name: str, + instance_pool_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.InstancePool]: + """Updates an instance pool. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param instance_pool_name: The name of the instance pool to be updated. Required. + :type instance_pool_name: str + :param parameters: The requested instance pool resource state. Required. + :type parameters: IO + :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 InstancePool or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.InstancePool] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_update( + self, + resource_group_name: str, + instance_pool_name: str, + parameters: Union[_models.InstancePoolUpdate, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.InstancePool]: + """Updates an instance pool. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param instance_pool_name: The name of the instance pool to be updated. Required. + :type instance_pool_name: str + :param parameters: The requested instance pool resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.InstancePoolUpdate 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. + :return: An instance of AsyncLROPoller that returns either InstancePool or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.InstancePool] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstancePool] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstancePool] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -494,78 +616,65 @@ async def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('InstancePool', pipeline_response) + deserialized = self._deserialize("InstancePool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore @distributed_trace - def list_by_resource_group( - self, - resource_group_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.InstancePoolListResult]: + def list_by_resource_group(self, resource_group_name: str, **kwargs: Any) -> AsyncIterable["_models.InstancePool"]: """Gets a list of instance pools in the resource group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either InstancePoolListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.InstancePoolListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either InstancePool or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.InstancePool] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstancePoolListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstancePoolListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_request( resource_group_name=resource_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_resource_group.metadata['url'], + template_url=self.list_by_resource_group.metadata["url"], headers=_headers, params=_params, ) @@ -573,15 +682,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -597,10 +698,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -610,45 +709,35 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools"} # type: ignore + list_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools"} # type: ignore @distributed_trace - def list( - self, - **kwargs: Any - ) -> AsyncIterable[_models.InstancePoolListResult]: + def list(self, **kwargs: Any) -> AsyncIterable["_models.InstancePool"]: """Gets a list of all instance pools in the subscription. - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either InstancePoolListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.InstancePoolListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either InstancePool or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.InstancePool] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstancePoolListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstancePoolListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_request( subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list.metadata['url'], + template_url=self.list.metadata["url"], headers=_headers, params=_params, ) @@ -656,14 +745,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_request( - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -679,10 +761,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -692,8 +772,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/instancePools"} # type: ignore + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/instancePools"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_ipv6_firewall_rules_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_ipv6_firewall_rules_operations.py index 8478c3d24c134..604aa150673c5 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_ipv6_firewall_rules_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_ipv6_firewall_rules_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._ipv6_firewall_rules_operations import build_create_or_update_request, build_delete_request, build_get_request, build_list_by_server_request -T = TypeVar('T') +from ...operations._ipv6_firewall_rules_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_server_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class IPv6FirewallRulesOperations: """ .. warning:: @@ -43,50 +56,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.IPv6FirewallRuleListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.IPv6FirewallRule"]: """Gets a list of IPv6 firewall rules. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either IPv6FirewallRuleListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.IPv6FirewallRuleListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either IPv6FirewallRule or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.IPv6FirewallRule] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.IPv6FirewallRuleListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.IPv6FirewallRuleListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -94,16 +97,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -119,10 +113,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -132,56 +124,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - firewall_rule_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, firewall_rule_name: str, **kwargs: Any ) -> _models.IPv6FirewallRule: """Gets an IPv6 firewall rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param firewall_rule_name: The name of the firewall rule. + :param firewall_rule_name: The name of the firewall rule. Required. :type firewall_rule_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: IPv6FirewallRule, or the result of cls(response) + :return: IPv6FirewallRule or the result of cls(response) :rtype: ~azure.mgmt.sql.models.IPv6FirewallRule - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.IPv6FirewallRule] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.IPv6FirewallRule] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, firewall_rule_name=firewall_rule_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -189,67 +169,134 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('IPv6FirewallRule', pipeline_response) + deserialized = self._deserialize("IPv6FirewallRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}"} # type: ignore + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}"} # type: ignore - - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, server_name: str, firewall_rule_name: str, parameters: _models.IPv6FirewallRule, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.IPv6FirewallRule: """Creates or updates an IPv6 firewall rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param firewall_rule_name: The name of the firewall rule. + :param firewall_rule_name: The name of the firewall rule. Required. :type firewall_rule_name: str :param parameters: The required parameters for creating or updating an IPv6 firewall rule. + Required. :type parameters: ~azure.mgmt.sql.models.IPv6FirewallRule - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: IPv6FirewallRule or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.IPv6FirewallRule + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + firewall_rule_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.IPv6FirewallRule: + """Creates or updates an IPv6 firewall rule. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param firewall_rule_name: The name of the firewall rule. Required. + :type firewall_rule_name: str + :param parameters: The required parameters for creating or updating an IPv6 firewall rule. + Required. + :type parameters: IO + :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: IPv6FirewallRule, or the result of cls(response) + :return: IPv6FirewallRule or the result of cls(response) :rtype: ~azure.mgmt.sql.models.IPv6FirewallRule - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + firewall_rule_name: str, + parameters: Union[_models.IPv6FirewallRule, IO], + **kwargs: Any + ) -> _models.IPv6FirewallRule: + """Creates or updates an IPv6 firewall rule. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param firewall_rule_name: The name of the firewall rule. Required. + :type firewall_rule_name: str + :param parameters: The required parameters for creating or updating an IPv6 firewall rule. Is + either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.IPv6FirewallRule 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 + :return: IPv6FirewallRule or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.IPv6FirewallRule + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.IPv6FirewallRule] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.IPv6FirewallRule] - _json = self._serialize.body(parameters, 'IPv6FirewallRule') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "IPv6FirewallRule") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -259,7 +306,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -267,10 +315,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -278,63 +325,52 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('IPv6FirewallRule', pipeline_response) + deserialized = self._deserialize("IPv6FirewallRule", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('IPv6FirewallRule', pipeline_response) + deserialized = self._deserialize("IPv6FirewallRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}"} # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - firewall_rule_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, firewall_rule_name: str, **kwargs: Any ) -> None: """Deletes an IPv6 firewall rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param firewall_rule_name: The name of the firewall rule. + :param firewall_rule_name: The name of the firewall rule. Required. :type firewall_rule_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, firewall_rule_name=firewall_rule_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -342,10 +378,9 @@ async def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 204]: @@ -355,5 +390,4 @@ async def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_agents_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_agents_operations.py index f721a4b6da63a..fd4e72aa410fe 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_agents_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_agents_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,18 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._job_agents_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_server_request, build_update_request_initial -T = TypeVar('T') +from ...operations._job_agents_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_server_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class JobAgentsOperations: """ .. warning:: @@ -45,48 +59,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.JobAgentListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.JobAgent"]: """Gets a list of job agents in a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobAgentListResult or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobAgentListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobAgent or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobAgent] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobAgentListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobAgentListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -94,16 +100,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -119,10 +116,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -132,56 +127,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, **kwargs: Any ) -> _models.JobAgent: """Gets a job agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent to be retrieved. + :param job_agent_name: The name of the job agent to be retrieved. Required. :type job_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobAgent, or the result of cls(response) + :return: JobAgent or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobAgent - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobAgent] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobAgent] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -189,49 +172,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobAgent', pipeline_response) + deserialized = self._deserialize("JobAgent", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, job_agent_name: str, - parameters: _models.JobAgent, + parameters: Union[_models.JobAgent, IO], **kwargs: Any ) -> Optional[_models.JobAgent]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.JobAgent]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.JobAgent]] - _json = self._serialize.body(parameters, 'JobAgent') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "JobAgent") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, @@ -239,7 +224,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -247,10 +233,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -259,42 +244,43 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('JobAgent', pipeline_response) + deserialized = self._deserialize("JobAgent", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('JobAgent', pipeline_response) + deserialized = self._deserialize("JobAgent", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, job_agent_name: str, parameters: _models.JobAgent, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.JobAgent]: """Creates or updates a job agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent to be created or updated. + :param job_agent_name: The name of the job agent to be created or updated. Required. :type job_agent_name: str - :param parameters: The requested job agent resource state. + :param parameters: The requested job agent resource state. Required. :type parameters: ~azure.mgmt.sql.models.JobAgent - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -306,20 +292,94 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either JobAgent or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.JobAgent] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.JobAgent]: + """Creates or updates a job agent. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent to be created or updated. Required. + :type job_agent_name: str + :param parameters: The requested job agent resource state. Required. + :type parameters: IO + :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 JobAgent or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.JobAgent] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + parameters: Union[_models.JobAgent, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.JobAgent]: + """Creates or updates a job agent. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent to be created or updated. Required. + :type job_agent_name: str + :param parameters: The requested job agent resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.JobAgent 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. + :return: An instance of AsyncLROPoller that returns either JobAgent or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.JobAgent] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobAgent] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobAgent] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -328,66 +388,55 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('JobAgent', pipeline_response) + deserialized = self._deserialize("JobAgent", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -395,10 +444,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -408,29 +456,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, server_name: str, job_agent_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes a job agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent to be deleted. + :param job_agent_name: The name of the job agent to be deleted. Required. :type job_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -441,80 +481,77 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore async def _update_initial( self, resource_group_name: str, server_name: str, job_agent_name: str, - parameters: _models.JobAgentUpdate, + parameters: Union[_models.JobAgentUpdate, IO], **kwargs: Any ) -> Optional[_models.JobAgent]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.JobAgent]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.JobAgent]] - _json = self._serialize.body(parameters, 'JobAgentUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "JobAgentUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, @@ -522,7 +559,8 @@ async def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -530,10 +568,9 @@ async def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -542,39 +579,116 @@ async def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('JobAgent', pipeline_response) + deserialized = self._deserialize("JobAgent", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore - + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore - @distributed_trace_async + @overload async def begin_update( self, resource_group_name: str, server_name: str, job_agent_name: str, parameters: _models.JobAgentUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.JobAgent]: """Updates a job agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent to be updated. + :param job_agent_name: The name of the job agent to be updated. Required. :type job_agent_name: str - :param parameters: The update to the job agent. + :param parameters: The update to the job agent. Required. :type parameters: ~azure.mgmt.sql.models.JobAgentUpdate - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 JobAgent or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.JobAgent] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.JobAgent]: + """Updates a job agent. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent to be updated. Required. + :type job_agent_name: str + :param parameters: The update to the job agent. Required. + :type parameters: IO + :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 JobAgent or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.JobAgent] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + parameters: Union[_models.JobAgentUpdate, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.JobAgent]: + """Updates a job agent. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent to be updated. Required. + :type job_agent_name: str + :param parameters: The update to the job agent. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.JobAgentUpdate 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 @@ -586,20 +700,17 @@ async def begin_update( :return: An instance of AsyncLROPoller that returns either JobAgent or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.JobAgent] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobAgent] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobAgent] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -608,36 +719,32 @@ async def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('JobAgent', pipeline_response) + deserialized = self._deserialize("JobAgent", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_credentials_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_credentials_operations.py index b87892dc06ec9..60b71372ce0e6 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_credentials_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_credentials_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._job_credentials_operations import build_create_or_update_request, build_delete_request, build_get_request, build_list_by_agent_request -T = TypeVar('T') +from ...operations._job_credentials_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_agent_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class JobCredentialsOperations: """ .. warning:: @@ -43,53 +56,43 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_agent( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.JobCredentialListResult]: + self, resource_group_name: str, server_name: str, job_agent_name: str, **kwargs: Any + ) -> AsyncIterable["_models.JobCredential"]: """Gets a list of jobs credentials. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobCredentialListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobCredentialListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobCredential or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobCredential] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobCredentialListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobCredentialListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_agent_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_agent.metadata['url'], + template_url=self.list_by_agent.metadata["url"], headers=_headers, params=_params, ) @@ -97,17 +100,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_agent_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -123,10 +116,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -136,52 +127,39 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_agent.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials"} # type: ignore + list_by_agent.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - credential_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, credential_name: str, **kwargs: Any ) -> _models.JobCredential: """Gets a jobs credential. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param credential_name: The name of the credential. + :param credential_name: The name of the credential. Required. :type credential_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobCredential, or the result of cls(response) + :return: JobCredential or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobCredential - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobCredential] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobCredential] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -189,7 +167,7 @@ async def get( credential_name=credential_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -197,27 +175,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobCredential', pipeline_response) + deserialized = self._deserialize("JobCredential", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}"} # type: ignore - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, @@ -225,42 +201,115 @@ async def create_or_update( job_agent_name: str, credential_name: str, parameters: _models.JobCredential, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.JobCredential: """Creates or updates a job credential. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param credential_name: The name of the credential. + :param credential_name: The name of the credential. Required. :type credential_name: str - :param parameters: The requested job credential state. + :param parameters: The requested job credential state. Required. :type parameters: ~azure.mgmt.sql.models.JobCredential - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: JobCredential, or the result of cls(response) + :return: JobCredential or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobCredential - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + credential_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.JobCredential: + """Creates or updates a job credential. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent. Required. + :type job_agent_name: str + :param credential_name: The name of the credential. Required. + :type credential_name: str + :param parameters: The requested job credential state. Required. + :type parameters: IO + :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: JobCredential or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.JobCredential + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + credential_name: str, + parameters: Union[_models.JobCredential, IO], + **kwargs: Any + ) -> _models.JobCredential: + """Creates or updates a job credential. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent. Required. + :type job_agent_name: str + :param credential_name: The name of the credential. Required. + :type credential_name: str + :param parameters: The requested job credential state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.JobCredential 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 + :return: JobCredential or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.JobCredential + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobCredential] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobCredential] - _json = self._serialize.body(parameters, 'JobCredential') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "JobCredential") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -271,7 +320,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -279,10 +329,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -290,59 +339,47 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('JobCredential', pipeline_response) + deserialized = self._deserialize("JobCredential", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('JobCredential', pipeline_response) + deserialized = self._deserialize("JobCredential", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}"} # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - credential_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, credential_name: str, **kwargs: Any ) -> None: """Deletes a job credential. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param credential_name: The name of the credential. + :param credential_name: The name of the credential. Required. :type credential_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -350,7 +387,7 @@ async def delete( # pylint: disable=inconsistent-return-statements credential_name=credential_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -358,10 +395,9 @@ async def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 204]: @@ -371,5 +407,4 @@ async def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_executions_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_executions_operations.py index f16f941511f04..555da67dc6fb6 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_executions_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_executions_operations.py @@ -10,7 +10,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -23,10 +29,19 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._job_executions_operations import build_cancel_request, build_create_or_update_request_initial, build_create_request_initial, build_get_request, build_list_by_agent_request, build_list_by_job_request -T = TypeVar('T') +from ...operations._job_executions_operations import ( + build_cancel_request, + build_create_or_update_request, + build_create_request, + build_get_request, + build_list_by_agent_request, + build_list_by_job_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class JobExecutionsOperations: """ .. warning:: @@ -46,7 +61,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_agent( self, @@ -61,15 +75,15 @@ def list_by_agent( skip: Optional[int] = None, top: Optional[int] = None, **kwargs: Any - ) -> AsyncIterable[_models.JobExecutionListResult]: + ) -> AsyncIterable["_models.JobExecution"]: """Lists all executions in a job agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str :param create_time_min: If specified, only job executions created at or after the specified time are included. Default value is None. @@ -90,34 +104,28 @@ def list_by_agent( :type skip: int :param top: The number of elements to return from the collection. Default value is None. :type top: int - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobExecutionListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobExecutionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobExecution or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobExecution] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecutionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecutionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_agent_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, subscription_id=self._config.subscription_id, - api_version=api_version, create_time_min=create_time_min, create_time_max=create_time_max, end_time_min=end_time_min, @@ -125,7 +133,8 @@ def prepare_request(next_link=None): is_active=is_active, skip=skip, top=top, - template_url=self.list_by_agent.metadata['url'], + api_version=api_version, + template_url=self.list_by_agent.metadata["url"], headers=_headers, params=_params, ) @@ -133,24 +142,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_agent_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - create_time_min=create_time_min, - create_time_max=create_time_max, - end_time_min=end_time_min, - end_time_max=end_time_max, - is_active=is_active, - skip=skip, - top=top, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -166,10 +158,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -179,11 +169,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_agent.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/executions"} # type: ignore + list_by_agent.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/executions"} # type: ignore @distributed_trace_async async def cancel( # pylint: disable=inconsistent-return-statements @@ -198,36 +186,30 @@ async def cancel( # pylint: disable=inconsistent-return-statements """Requests cancellation of a job execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job. + :param job_name: The name of the job. Required. :type job_name: str - :param job_execution_id: The id of the job execution to cancel. + :param job_execution_id: The id of the job execution to cancel. Required. :type job_execution_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_cancel_request( resource_group_name=resource_group_name, server_name=server_name, @@ -236,7 +218,7 @@ async def cancel( # pylint: disable=inconsistent-return-statements job_execution_id=job_execution_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.cancel.metadata['url'], + template_url=self.cancel.metadata["url"], headers=_headers, params=_params, ) @@ -244,10 +226,9 @@ async def cancel( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -257,37 +238,28 @@ async def cancel( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - cancel.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/cancel"} # type: ignore - + cancel.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/cancel"} # type: ignore async def _create_initial( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, **kwargs: Any ) -> Optional[_models.JobExecution]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.JobExecution]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.JobExecution]] - - request = build_create_request_initial( + request = build_create_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, job_name=job_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._create_initial.metadata['url'], + template_url=self._create_initial.metadata["url"], headers=_headers, params=_params, ) @@ -295,10 +267,9 @@ async def _create_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -307,39 +278,30 @@ async def _create_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('JobExecution', pipeline_response) + deserialized = self._deserialize("JobExecution", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/start"} # type: ignore - + _create_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/start"} # type: ignore @distributed_trace_async async def begin_create( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, **kwargs: Any ) -> AsyncLROPoller[_models.JobExecution]: """Starts an elastic job execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -351,19 +313,16 @@ async def begin_create( :return: An instance of AsyncLROPoller that returns either JobExecution or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.JobExecution] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecution] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecution] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_initial( # type: ignore resource_group_name=resource_group_name, @@ -371,39 +330,35 @@ async def begin_create( job_agent_name=job_agent_name, job_name=job_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('JobExecution', pipeline_response) + deserialized = self._deserialize("JobExecution", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_create.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/start"} # type: ignore + begin_create.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/start"} # type: ignore @distributed_trace def list_by_job( @@ -420,17 +375,17 @@ def list_by_job( skip: Optional[int] = None, top: Optional[int] = None, **kwargs: Any - ) -> AsyncIterable[_models.JobExecutionListResult]: + ) -> AsyncIterable["_models.JobExecution"]: """Lists a job's executions. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str :param create_time_min: If specified, only job executions created at or after the specified time are included. Default value is None. @@ -451,35 +406,29 @@ def list_by_job( :type skip: int :param top: The number of elements to return from the collection. Default value is None. :type top: int - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobExecutionListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobExecutionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobExecution or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobExecution] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecutionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecutionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_job_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, job_name=job_name, subscription_id=self._config.subscription_id, - api_version=api_version, create_time_min=create_time_min, create_time_max=create_time_max, end_time_min=end_time_min, @@ -487,7 +436,8 @@ def prepare_request(next_link=None): is_active=is_active, skip=skip, top=top, - template_url=self.list_by_job.metadata['url'], + api_version=api_version, + template_url=self.list_by_job.metadata["url"], headers=_headers, params=_params, ) @@ -495,25 +445,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_job_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - job_name=job_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - create_time_min=create_time_min, - create_time_max=create_time_max, - end_time_min=end_time_min, - end_time_max=end_time_max, - is_active=is_active, - skip=skip, - top=top, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -529,10 +461,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -542,11 +472,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_job.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions"} # type: ignore + list_by_job.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions"} # type: ignore @distributed_trace_async async def get( @@ -561,36 +489,30 @@ async def get( """Gets a job execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job. + :param job_name: The name of the job. Required. :type job_name: str - :param job_execution_id: The id of the job execution. + :param job_execution_id: The id of the job execution. Required. :type job_execution_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobExecution, or the result of cls(response) + :return: JobExecution or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobExecution - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecution] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecution] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -599,7 +521,7 @@ async def get( job_execution_id=job_execution_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -607,25 +529,23 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobExecution', pipeline_response) + deserialized = self._deserialize("JobExecution", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}"} # type: ignore async def _create_or_update_initial( self, @@ -636,19 +556,16 @@ async def _create_or_update_initial( job_execution_id: str, **kwargs: Any ) -> Optional[_models.JobExecution]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.JobExecution]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.JobExecution]] - - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, @@ -656,7 +573,7 @@ async def _create_or_update_initial( job_execution_id=job_execution_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._create_or_update_initial.metadata['url'], + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -664,10 +581,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -676,18 +592,17 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('JobExecution', pipeline_response) + deserialized = self._deserialize("JobExecution", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('JobExecution', pipeline_response) + deserialized = self._deserialize("JobExecution", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}"} # type: ignore @distributed_trace_async async def begin_create_or_update( @@ -702,19 +617,16 @@ async def begin_create_or_update( """Creates or updates a job execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :param job_execution_id: The job execution id to create the job execution under. + :param job_execution_id: The job execution id to create the job execution under. Required. :type job_execution_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -726,19 +638,16 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either JobExecution or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.JobExecution] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecution] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecution] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -747,36 +656,32 @@ async def begin_create_or_update( job_name=job_name, job_execution_id=job_execution_id, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('JobExecution', pipeline_response) + deserialized = self._deserialize("JobExecution", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_step_executions_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_step_executions_operations.py index b3ca2d55bca0c..b5579e39bc987 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_step_executions_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_step_executions_operations.py @@ -10,7 +10,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -22,9 +28,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._job_step_executions_operations import build_get_request, build_list_by_job_execution_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class JobStepExecutionsOperations: """ .. warning:: @@ -44,7 +52,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_job_execution( self, @@ -61,19 +68,19 @@ def list_by_job_execution( skip: Optional[int] = None, top: Optional[int] = None, **kwargs: Any - ) -> AsyncIterable[_models.JobExecutionListResult]: + ) -> AsyncIterable["_models.JobExecution"]: """Lists the step executions of a job execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :param job_execution_id: The id of the job execution. + :param job_execution_id: The id of the job execution. Required. :type job_execution_id: str :param create_time_min: If specified, only job executions created at or after the specified time are included. Default value is None. @@ -94,28 +101,23 @@ def list_by_job_execution( :type skip: int :param top: The number of elements to return from the collection. Default value is None. :type top: int - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobExecutionListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobExecutionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobExecution or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobExecution] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecutionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecutionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_job_execution_request( resource_group_name=resource_group_name, server_name=server_name, @@ -123,7 +125,6 @@ def prepare_request(next_link=None): job_name=job_name, job_execution_id=job_execution_id, subscription_id=self._config.subscription_id, - api_version=api_version, create_time_min=create_time_min, create_time_max=create_time_max, end_time_min=end_time_min, @@ -131,7 +132,8 @@ def prepare_request(next_link=None): is_active=is_active, skip=skip, top=top, - template_url=self.list_by_job_execution.metadata['url'], + api_version=api_version, + template_url=self.list_by_job_execution.metadata["url"], headers=_headers, params=_params, ) @@ -139,26 +141,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_job_execution_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - job_name=job_name, - job_execution_id=job_execution_id, - subscription_id=self._config.subscription_id, - api_version=api_version, - create_time_min=create_time_min, - create_time_max=create_time_max, - end_time_min=end_time_min, - end_time_max=end_time_max, - is_active=is_active, - skip=skip, - top=top, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -174,10 +157,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -187,11 +168,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_job_execution.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps"} # type: ignore + list_by_job_execution.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps"} # type: ignore @distributed_trace_async async def get( @@ -207,38 +186,32 @@ async def get( """Gets a step execution of a job execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :param job_execution_id: The unique id of the job execution. + :param job_execution_id: The unique id of the job execution. Required. :type job_execution_id: str - :param step_name: The name of the step. + :param step_name: The name of the step. Required. :type step_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobExecution, or the result of cls(response) + :return: JobExecution or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobExecution - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecution] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecution] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -248,7 +221,7 @@ async def get( step_name=step_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -256,22 +229,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobExecution', pipeline_response) + deserialized = self._deserialize("JobExecution", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_steps_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_steps_operations.py index ce0196fae9d2f..88741e53c1ec2 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_steps_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_steps_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,19 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._job_steps_operations import build_create_or_update_request, build_delete_request, build_get_by_version_request, build_get_request, build_list_by_job_request, build_list_by_version_request -T = TypeVar('T') +from ...operations._job_steps_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_by_version_request, + build_get_request, + build_list_by_job_request, + build_list_by_version_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class JobStepsOperations: """ .. warning:: @@ -43,7 +58,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_version( self, @@ -53,41 +67,37 @@ def list_by_version( job_name: str, job_version: int, **kwargs: Any - ) -> AsyncIterable[_models.JobStepListResult]: + ) -> AsyncIterable["_models.JobStep"]: """Gets all job steps in the specified job version. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :param job_version: The version of the job to get. + :param job_version: The version of the job to get. Required. :type job_version: int - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobStepListResult or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobStepListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobStep or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobStep] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobStepListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobStepListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_version_request( resource_group_name=resource_group_name, server_name=server_name, @@ -96,7 +106,7 @@ def prepare_request(next_link=None): job_version=job_version, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_version.metadata['url'], + template_url=self.list_by_version.metadata["url"], headers=_headers, params=_params, ) @@ -104,19 +114,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_version_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - job_name=job_name, - job_version=job_version, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -132,10 +130,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -145,11 +141,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_version.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}/steps"} # type: ignore + list_by_version.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}/steps"} # type: ignore @distributed_trace_async async def get_by_version( @@ -165,38 +159,32 @@ async def get_by_version( """Gets the specified version of a job step. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job. + :param job_name: The name of the job. Required. :type job_name: str - :param job_version: The version of the job to get. + :param job_version: The version of the job to get. Required. :type job_version: int - :param step_name: The name of the job step. + :param step_name: The name of the job step. Required. :type step_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobStep, or the result of cls(response) + :return: JobStep or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobStep - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobStep] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobStep] - request = build_get_by_version_request( resource_group_name=resource_group_name, server_name=server_name, @@ -206,7 +194,7 @@ async def get_by_version( step_name=step_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get_by_version.metadata['url'], + template_url=self.get_by_version.metadata["url"], headers=_headers, params=_params, ) @@ -214,67 +202,56 @@ async def get_by_version( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobStep', pipeline_response) + deserialized = self._deserialize("JobStep", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get_by_version.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}/steps/{stepName}"} # type: ignore - + get_by_version.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}/steps/{stepName}"} # type: ignore @distributed_trace def list_by_job( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.JobStepListResult]: + self, resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, **kwargs: Any + ) -> AsyncIterable["_models.JobStep"]: """Gets all job steps for a job's current version. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobStepListResult or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobStepListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobStep or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobStep] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobStepListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobStepListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_job_request( resource_group_name=resource_group_name, server_name=server_name, @@ -282,7 +259,7 @@ def prepare_request(next_link=None): job_name=job_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_job.metadata['url'], + template_url=self.list_by_job.metadata["url"], headers=_headers, params=_params, ) @@ -290,18 +267,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_job_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - job_name=job_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -317,10 +283,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -330,11 +294,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_job.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps"} # type: ignore + list_by_job.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps"} # type: ignore @distributed_trace_async async def get( @@ -349,36 +311,30 @@ async def get( """Gets a job step in a job's current version. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job. + :param job_name: The name of the job. Required. :type job_name: str - :param step_name: The name of the job step. + :param step_name: The name of the job step. Required. :type step_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobStep, or the result of cls(response) + :return: JobStep or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobStep - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobStep] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobStep] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -387,7 +343,7 @@ async def get( step_name=step_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -395,27 +351,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobStep', pipeline_response) + deserialized = self._deserialize("JobStep", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}"} # type: ignore - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, @@ -424,44 +378,123 @@ async def create_or_update( job_name: str, step_name: str, parameters: _models.JobStep, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.JobStep: """Creates or updates a job step. This will implicitly create a new job version. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job. + :param job_name: The name of the job. Required. :type job_name: str - :param step_name: The name of the job step. + :param step_name: The name of the job step. Required. :type step_name: str - :param parameters: The requested state of the job step. + :param parameters: The requested state of the job step. Required. :type parameters: ~azure.mgmt.sql.models.JobStep - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: JobStep, or the result of cls(response) + :return: JobStep or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobStep - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + job_name: str, + step_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.JobStep: + """Creates or updates a job step. This will implicitly create a new job version. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent. Required. + :type job_agent_name: str + :param job_name: The name of the job. Required. + :type job_name: str + :param step_name: The name of the job step. Required. + :type step_name: str + :param parameters: The requested state of the job step. Required. + :type parameters: IO + :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: JobStep or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.JobStep + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + job_name: str, + step_name: str, + parameters: Union[_models.JobStep, IO], + **kwargs: Any + ) -> _models.JobStep: + """Creates or updates a job step. This will implicitly create a new job version. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent. Required. + :type job_agent_name: str + :param job_name: The name of the job. Required. + :type job_name: str + :param step_name: The name of the job step. Required. + :type step_name: str + :param parameters: The requested state of the job step. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.JobStep 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 + :return: JobStep or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.JobStep + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobStep] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobStep] - _json = self._serialize.body(parameters, 'JobStep') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "JobStep") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -473,7 +506,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -481,10 +515,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -492,18 +525,17 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('JobStep', pipeline_response) + deserialized = self._deserialize("JobStep", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('JobStep', pipeline_response) + deserialized = self._deserialize("JobStep", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}"} # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -518,36 +550,30 @@ async def delete( # pylint: disable=inconsistent-return-statements """Deletes a job step. This will implicitly create a new job version. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job. + :param job_name: The name of the job. Required. :type job_name: str - :param step_name: The name of the job step to delete. + :param step_name: The name of the job step to delete. Required. :type step_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -556,7 +582,7 @@ async def delete( # pylint: disable=inconsistent-return-statements step_name=step_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -564,10 +590,9 @@ async def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 204]: @@ -577,5 +602,4 @@ async def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_target_executions_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_target_executions_operations.py index 71fa50becf9d0..533fb9d0ca788 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_target_executions_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_target_executions_operations.py @@ -10,7 +10,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,10 +27,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._job_target_executions_operations import build_get_request, build_list_by_job_execution_request, build_list_by_step_request -T = TypeVar('T') +from ...operations._job_target_executions_operations import ( + build_get_request, + build_list_by_job_execution_request, + build_list_by_step_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class JobTargetExecutionsOperations: """ .. warning:: @@ -44,7 +56,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_job_execution( self, @@ -61,19 +72,19 @@ def list_by_job_execution( skip: Optional[int] = None, top: Optional[int] = None, **kwargs: Any - ) -> AsyncIterable[_models.JobExecutionListResult]: + ) -> AsyncIterable["_models.JobExecution"]: """Lists target executions for all steps of a job execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :param job_execution_id: The id of the job execution. + :param job_execution_id: The id of the job execution. Required. :type job_execution_id: str :param create_time_min: If specified, only job executions created at or after the specified time are included. Default value is None. @@ -94,28 +105,23 @@ def list_by_job_execution( :type skip: int :param top: The number of elements to return from the collection. Default value is None. :type top: int - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobExecutionListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobExecutionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobExecution or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobExecution] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecutionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecutionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_job_execution_request( resource_group_name=resource_group_name, server_name=server_name, @@ -123,7 +129,6 @@ def prepare_request(next_link=None): job_name=job_name, job_execution_id=job_execution_id, subscription_id=self._config.subscription_id, - api_version=api_version, create_time_min=create_time_min, create_time_max=create_time_max, end_time_min=end_time_min, @@ -131,7 +136,8 @@ def prepare_request(next_link=None): is_active=is_active, skip=skip, top=top, - template_url=self.list_by_job_execution.metadata['url'], + api_version=api_version, + template_url=self.list_by_job_execution.metadata["url"], headers=_headers, params=_params, ) @@ -139,26 +145,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_job_execution_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - job_name=job_name, - job_execution_id=job_execution_id, - subscription_id=self._config.subscription_id, - api_version=api_version, - create_time_min=create_time_min, - create_time_max=create_time_max, - end_time_min=end_time_min, - end_time_max=end_time_max, - is_active=is_active, - skip=skip, - top=top, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -174,10 +161,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -187,11 +172,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_job_execution.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/targets"} # type: ignore + list_by_job_execution.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/targets"} # type: ignore @distributed_trace def list_by_step( @@ -210,21 +193,21 @@ def list_by_step( skip: Optional[int] = None, top: Optional[int] = None, **kwargs: Any - ) -> AsyncIterable[_models.JobExecutionListResult]: + ) -> AsyncIterable["_models.JobExecution"]: """Lists the target executions of a job step execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :param job_execution_id: The id of the job execution. + :param job_execution_id: The id of the job execution. Required. :type job_execution_id: str - :param step_name: The name of the step. + :param step_name: The name of the step. Required. :type step_name: str :param create_time_min: If specified, only job executions created at or after the specified time are included. Default value is None. @@ -245,28 +228,23 @@ def list_by_step( :type skip: int :param top: The number of elements to return from the collection. Default value is None. :type top: int - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobExecutionListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobExecutionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobExecution or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobExecution] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecutionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecutionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_step_request( resource_group_name=resource_group_name, server_name=server_name, @@ -275,7 +253,6 @@ def prepare_request(next_link=None): job_execution_id=job_execution_id, step_name=step_name, subscription_id=self._config.subscription_id, - api_version=api_version, create_time_min=create_time_min, create_time_max=create_time_max, end_time_min=end_time_min, @@ -283,7 +260,8 @@ def prepare_request(next_link=None): is_active=is_active, skip=skip, top=top, - template_url=self.list_by_step.metadata['url'], + api_version=api_version, + template_url=self.list_by_step.metadata["url"], headers=_headers, params=_params, ) @@ -291,27 +269,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_step_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - job_name=job_name, - job_execution_id=job_execution_id, - step_name=step_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - create_time_min=create_time_min, - create_time_max=create_time_max, - end_time_min=end_time_min, - end_time_max=end_time_max, - is_active=is_active, - skip=skip, - top=top, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -327,10 +285,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -340,11 +296,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_step.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}/targets"} # type: ignore + list_by_step.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}/targets"} # type: ignore @distributed_trace_async async def get( @@ -361,40 +315,34 @@ async def get( """Gets a target execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :param job_execution_id: The unique id of the job execution. + :param job_execution_id: The unique id of the job execution. Required. :type job_execution_id: str - :param step_name: The name of the step. + :param step_name: The name of the step. Required. :type step_name: str - :param target_id: The target id. + :param target_id: The target id. Required. :type target_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobExecution, or the result of cls(response) + :return: JobExecution or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobExecution - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecution] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecution] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -405,7 +353,7 @@ async def get( target_id=target_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -413,22 +361,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobExecution', pipeline_response) + deserialized = self._deserialize("JobExecution", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}/targets/{targetId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}/targets/{targetId}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_target_groups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_target_groups_operations.py index 9c01a39e0368d..e39a0896e6a40 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_target_groups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_target_groups_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._job_target_groups_operations import build_create_or_update_request, build_delete_request, build_get_request, build_list_by_agent_request -T = TypeVar('T') +from ...operations._job_target_groups_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_agent_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class JobTargetGroupsOperations: """ .. warning:: @@ -43,54 +56,43 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_agent( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.JobTargetGroupListResult]: + self, resource_group_name: str, server_name: str, job_agent_name: str, **kwargs: Any + ) -> AsyncIterable["_models.JobTargetGroup"]: """Gets all target groups in an agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobTargetGroupListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobTargetGroupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobTargetGroup or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobTargetGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobTargetGroupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobTargetGroupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_agent_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_agent.metadata['url'], + template_url=self.list_by_agent.metadata["url"], headers=_headers, params=_params, ) @@ -98,17 +100,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_agent_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -124,10 +116,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -137,52 +127,39 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_agent.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups"} # type: ignore + list_by_agent.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - target_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, target_group_name: str, **kwargs: Any ) -> _models.JobTargetGroup: """Gets a target group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param target_group_name: The name of the target group. + :param target_group_name: The name of the target group. Required. :type target_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobTargetGroup, or the result of cls(response) + :return: JobTargetGroup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobTargetGroup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobTargetGroup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobTargetGroup] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -190,7 +167,7 @@ async def get( target_group_name=target_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -198,27 +175,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobTargetGroup', pipeline_response) + deserialized = self._deserialize("JobTargetGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}"} # type: ignore - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, @@ -226,42 +201,115 @@ async def create_or_update( job_agent_name: str, target_group_name: str, parameters: _models.JobTargetGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.JobTargetGroup: """Creates or updates a target group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param target_group_name: The name of the target group. + :param target_group_name: The name of the target group. Required. :type target_group_name: str - :param parameters: The requested state of the target group. + :param parameters: The requested state of the target group. Required. :type parameters: ~azure.mgmt.sql.models.JobTargetGroup - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: JobTargetGroup, or the result of cls(response) + :return: JobTargetGroup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobTargetGroup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + target_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.JobTargetGroup: + """Creates or updates a target group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent. Required. + :type job_agent_name: str + :param target_group_name: The name of the target group. Required. + :type target_group_name: str + :param parameters: The requested state of the target group. Required. + :type parameters: IO + :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: JobTargetGroup or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.JobTargetGroup + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + target_group_name: str, + parameters: Union[_models.JobTargetGroup, IO], + **kwargs: Any + ) -> _models.JobTargetGroup: + """Creates or updates a target group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent. Required. + :type job_agent_name: str + :param target_group_name: The name of the target group. Required. + :type target_group_name: str + :param parameters: The requested state of the target group. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.JobTargetGroup 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 + :return: JobTargetGroup or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.JobTargetGroup + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobTargetGroup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobTargetGroup] - _json = self._serialize.body(parameters, 'JobTargetGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "JobTargetGroup") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -272,7 +320,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -280,10 +329,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -291,59 +339,47 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('JobTargetGroup', pipeline_response) + deserialized = self._deserialize("JobTargetGroup", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('JobTargetGroup', pipeline_response) + deserialized = self._deserialize("JobTargetGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}"} # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - target_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, target_group_name: str, **kwargs: Any ) -> None: """Deletes a target group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param target_group_name: The name of the target group. + :param target_group_name: The name of the target group. Required. :type target_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -351,7 +387,7 @@ async def delete( # pylint: disable=inconsistent-return-statements target_group_name=target_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -359,10 +395,9 @@ async def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 204]: @@ -372,5 +407,4 @@ async def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_versions_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_versions_operations.py index 64a8c2a44a3c7..e0293bc4fb52e 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_versions_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_job_versions_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._job_versions_operations import build_get_request, build_list_by_job_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class JobVersionsOperations: """ .. warning:: @@ -43,49 +51,38 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_job( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.JobVersionListResult]: + self, resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, **kwargs: Any + ) -> AsyncIterable["_models.JobVersion"]: """Gets all versions of a job. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobVersionListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobVersionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobVersion or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobVersion] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobVersionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobVersionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_job_request( resource_group_name=resource_group_name, server_name=server_name, @@ -93,7 +90,7 @@ def prepare_request(next_link=None): job_name=job_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_job.metadata['url'], + template_url=self.list_by_job.metadata["url"], headers=_headers, params=_params, ) @@ -101,18 +98,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_job_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - job_name=job_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -128,10 +114,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -141,11 +125,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_job.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions"} # type: ignore + list_by_job.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions"} # type: ignore @distributed_trace_async async def get( @@ -160,36 +142,30 @@ async def get( """Gets a job version. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job. + :param job_name: The name of the job. Required. :type job_name: str - :param job_version: The version of the job to get. + :param job_version: The version of the job to get. Required. :type job_version: int - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobVersion, or the result of cls(response) + :return: JobVersion or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobVersion - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobVersion] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobVersion] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -198,7 +174,7 @@ async def get( job_version=job_version, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -206,22 +182,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobVersion', pipeline_response) + deserialized = self._deserialize("JobVersion", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_jobs_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_jobs_operations.py index 19df97c409880..b107e11927085 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_jobs_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_jobs_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._jobs_operations import build_create_or_update_request, build_delete_request, build_get_request, build_list_by_agent_request -T = TypeVar('T') +from ...operations._jobs_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_agent_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class JobsOperations: """ .. warning:: @@ -43,52 +56,43 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_agent( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.JobListResult]: + self, resource_group_name: str, server_name: str, job_agent_name: str, **kwargs: Any + ) -> AsyncIterable["_models.Job"]: """Gets a list of jobs. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobListResult or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.JobListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Job or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.Job] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_agent_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_agent.metadata['url'], + template_url=self.list_by_agent.metadata["url"], headers=_headers, params=_params, ) @@ -96,17 +100,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_agent_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -122,10 +116,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -135,52 +127,39 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_agent.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs"} # type: ignore + list_by_agent.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, **kwargs: Any ) -> _models.Job: """Gets a job. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Job, or the result of cls(response) + :return: Job or the result of cls(response) :rtype: ~azure.mgmt.sql.models.Job - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.Job] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.Job] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -188,7 +167,7 @@ async def get( job_name=job_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -196,27 +175,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('Job', pipeline_response) + deserialized = self._deserialize("Job", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}"} # type: ignore - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, @@ -224,42 +201,114 @@ async def create_or_update( job_agent_name: str, job_name: str, parameters: _models.Job, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.Job: """Creates or updates a job. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :param parameters: The requested job state. + :param parameters: The requested job state. Required. :type parameters: ~azure.mgmt.sql.models.Job - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: Job, or the result of cls(response) + :return: Job or the result of cls(response) :rtype: ~azure.mgmt.sql.models.Job - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + job_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.Job: + """Creates or updates a job. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent. Required. + :type job_agent_name: str + :param job_name: The name of the job to get. Required. + :type job_name: str + :param parameters: The requested job state. Required. + :type parameters: IO + :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: Job or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.Job + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + job_name: str, + parameters: Union[_models.Job, IO], + **kwargs: Any + ) -> _models.Job: + """Creates or updates a job. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent. Required. + :type job_agent_name: str + :param job_name: The name of the job to get. Required. + :type job_name: str + :param parameters: The requested job state. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.Job 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 + :return: Job or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.Job + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.Job] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.Job] - _json = self._serialize.body(parameters, 'Job') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "Job") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -270,7 +319,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -278,10 +328,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -289,59 +338,47 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('Job', pipeline_response) + deserialized = self._deserialize("Job", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('Job', pipeline_response) + deserialized = self._deserialize("Job", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}"} # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, **kwargs: Any ) -> None: """Deletes a job. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to delete. + :param job_name: The name of the job to delete. Required. :type job_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -349,7 +386,7 @@ async def delete( # pylint: disable=inconsistent-return-statements job_name=job_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -357,10 +394,9 @@ async def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 204]: @@ -370,5 +406,4 @@ async def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_ledger_digest_uploads_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_ledger_digest_uploads_operations.py index e0130f5978e41..0452fcd5f36cf 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_ledger_digest_uploads_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_ledger_digest_uploads_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._ledger_digest_uploads_operations import build_create_or_update_request_initial, build_disable_request_initial, build_get_request, build_list_by_database_request -T = TypeVar('T') +from ...operations._ledger_digest_uploads_operations import ( + build_create_or_update_request, + build_disable_request, + build_get_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class LedgerDigestUploadsOperations: """ .. warning:: @@ -45,7 +58,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -58,34 +70,28 @@ async def get( """Gets the current ledger digest upload configuration for a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param ledger_digest_uploads: + :param ledger_digest_uploads: "current" Required. :type ledger_digest_uploads: str or ~azure.mgmt.sql.models.LedgerDigestUploadsName - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: LedgerDigestUploads, or the result of cls(response) + :return: LedgerDigestUploads or the result of cls(response) :rtype: ~azure.mgmt.sql.models.LedgerDigestUploads - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LedgerDigestUploads] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LedgerDigestUploads] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -93,7 +99,7 @@ async def get( ledger_digest_uploads=ledger_digest_uploads, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -101,25 +107,23 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('LedgerDigestUploads', pipeline_response) + deserialized = self._deserialize("LedgerDigestUploads", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}"} # type: ignore async def _create_or_update_initial( self, @@ -127,24 +131,28 @@ async def _create_or_update_initial( server_name: str, database_name: str, ledger_digest_uploads: Union[str, "_models.LedgerDigestUploadsName"], - parameters: _models.LedgerDigestUploads, + parameters: Union[_models.LedgerDigestUploads, IO], **kwargs: Any ) -> Optional[_models.LedgerDigestUploads]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.LedgerDigestUploads]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.LedgerDigestUploads]] - _json = self._serialize.body(parameters, 'LedgerDigestUploads') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "LedgerDigestUploads") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -153,7 +161,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -161,10 +170,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -173,17 +181,16 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('LedgerDigestUploads', pipeline_response) + deserialized = self._deserialize("LedgerDigestUploads", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}"} # type: ignore - - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, @@ -191,25 +198,111 @@ async def begin_create_or_update( database_name: str, ledger_digest_uploads: Union[str, "_models.LedgerDigestUploadsName"], parameters: _models.LedgerDigestUploads, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.LedgerDigestUploads]: """Enables upload ledger digests to an Azure Storage account or an Azure Confidential Ledger instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param ledger_digest_uploads: + :param ledger_digest_uploads: "current" Required. :type ledger_digest_uploads: str or ~azure.mgmt.sql.models.LedgerDigestUploadsName - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.LedgerDigestUploads - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 LedgerDigestUploads or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LedgerDigestUploads] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + ledger_digest_uploads: Union[str, "_models.LedgerDigestUploadsName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.LedgerDigestUploads]: + """Enables upload ledger digests to an Azure Storage account or an Azure Confidential Ledger + instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param ledger_digest_uploads: "current" Required. + :type ledger_digest_uploads: str or ~azure.mgmt.sql.models.LedgerDigestUploadsName + :param parameters: Required. + :type parameters: IO + :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 LedgerDigestUploads or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LedgerDigestUploads] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + ledger_digest_uploads: Union[str, "_models.LedgerDigestUploadsName"], + parameters: Union[_models.LedgerDigestUploads, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.LedgerDigestUploads]: + """Enables upload ledger digests to an Azure Storage account or an Azure Confidential Ledger + instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param ledger_digest_uploads: "current" Required. + :type ledger_digest_uploads: str or ~azure.mgmt.sql.models.LedgerDigestUploadsName + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.LedgerDigestUploads 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 @@ -221,20 +314,17 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either LedgerDigestUploads or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LedgerDigestUploads] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.LedgerDigestUploads] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.LedgerDigestUploads] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -244,87 +334,73 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('LedgerDigestUploads', pipeline_response) + deserialized = self._deserialize("LedgerDigestUploads", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.LedgerDigestUploadsListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.LedgerDigestUploads"]: """Gets all ledger digest upload settings on a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LedgerDigestUploadsListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LedgerDigestUploadsListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either LedgerDigestUploads or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LedgerDigestUploads] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LedgerDigestUploadsListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LedgerDigestUploadsListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -332,17 +408,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -358,10 +424,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -371,11 +435,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads"} # type: ignore async def _disable_initial( self, @@ -385,26 +447,23 @@ async def _disable_initial( ledger_digest_uploads: Union[str, "_models.LedgerDigestUploadsName"], **kwargs: Any ) -> Optional[_models.LedgerDigestUploads]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.LedgerDigestUploads]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.LedgerDigestUploads]] - - request = build_disable_request_initial( + request = build_disable_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, ledger_digest_uploads=ledger_digest_uploads, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._disable_initial.metadata['url'], + template_url=self._disable_initial.metadata["url"], headers=_headers, params=_params, ) @@ -412,10 +471,9 @@ async def _disable_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -424,15 +482,14 @@ async def _disable_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('LedgerDigestUploads', pipeline_response) + deserialized = self._deserialize("LedgerDigestUploads", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _disable_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}/disable"} # type: ignore - + _disable_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}/disable"} # type: ignore @distributed_trace_async async def begin_disable( @@ -447,17 +504,14 @@ async def begin_disable( instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param ledger_digest_uploads: + :param ledger_digest_uploads: "current" Required. :type ledger_digest_uploads: str or ~azure.mgmt.sql.models.LedgerDigestUploadsName - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -469,19 +523,16 @@ async def begin_disable( :return: An instance of AsyncLROPoller that returns either LedgerDigestUploads or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LedgerDigestUploads] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LedgerDigestUploads] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LedgerDigestUploads] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._disable_initial( # type: ignore resource_group_name=resource_group_name, @@ -489,36 +540,32 @@ async def begin_disable( database_name=database_name, ledger_digest_uploads=ledger_digest_uploads, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('LedgerDigestUploads', pipeline_response) + deserialized = self._deserialize("LedgerDigestUploads", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_disable.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}/disable"} # type: ignore + begin_disable.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}/disable"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_long_term_retention_backups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_long_term_retention_backups_operations.py index 8cd0e18a97534..71033183974cc 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_long_term_retention_backups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_long_term_retention_backups_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,27 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._long_term_retention_backups_operations import build_copy_by_resource_group_request_initial, build_copy_request_initial, build_delete_by_resource_group_request_initial, build_delete_request_initial, build_get_by_resource_group_request, build_get_request, build_list_by_database_request, build_list_by_location_request, build_list_by_resource_group_database_request, build_list_by_resource_group_location_request, build_list_by_resource_group_server_request, build_list_by_server_request, build_update_by_resource_group_request_initial, build_update_request_initial -T = TypeVar('T') +from ...operations._long_term_retention_backups_operations import ( + build_copy_by_resource_group_request, + build_copy_request, + build_delete_by_resource_group_request, + build_delete_request, + build_get_by_resource_group_request, + build_get_request, + build_list_by_database_request, + build_list_by_location_request, + build_list_by_resource_group_database_request, + build_list_by_resource_group_location_request, + build_list_by_resource_group_server_request, + build_list_by_server_request, + build_update_by_resource_group_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class LongTermRetentionBackupsOperations: """ .. warning:: @@ -45,31 +68,34 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - async def _copy_initial( self, location_name: str, long_term_retention_server_name: str, long_term_retention_database_name: str, backup_name: str, - parameters: _models.CopyLongTermRetentionBackupParameters, + parameters: Union[_models.CopyLongTermRetentionBackupParameters, IO], **kwargs: Any ) -> Optional[_models.LongTermRetentionBackupOperationResult]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.LongTermRetentionBackupOperationResult]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.LongTermRetentionBackupOperationResult]] - _json = self._serialize.body(parameters, 'CopyLongTermRetentionBackupParameters') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "CopyLongTermRetentionBackupParameters") - request = build_copy_request_initial( + request = build_copy_request( location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, long_term_retention_database_name=long_term_retention_database_name, @@ -78,7 +104,8 @@ async def _copy_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._copy_initial.metadata['url'], + content=_content, + template_url=self._copy_initial.metadata["url"], headers=_headers, params=_params, ) @@ -86,10 +113,9 @@ async def _copy_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -98,17 +124,16 @@ async def _copy_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('LongTermRetentionBackupOperationResult', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackupOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _copy_initial.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy"} # type: ignore + _copy_initial.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy"} # type: ignore - - @distributed_trace_async + @overload async def begin_copy( self, location_name: str, @@ -116,23 +141,108 @@ async def begin_copy( long_term_retention_database_name: str, backup_name: str, parameters: _models.CopyLongTermRetentionBackupParameters, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.LongTermRetentionBackupOperationResult]: """Copy an existing long term retention backup. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :param parameters: The parameters needed for long term retention copy request. + :param parameters: The parameters needed for long term retention copy request. Required. :type parameters: ~azure.mgmt.sql.models.CopyLongTermRetentionBackupParameters - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 + LongTermRetentionBackupOperationResult or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_copy( + self, + location_name: str, + long_term_retention_server_name: str, + long_term_retention_database_name: str, + backup_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.LongTermRetentionBackupOperationResult]: + """Copy an existing long term retention backup. + + :param location_name: The location of the database. Required. + :type location_name: str + :param long_term_retention_server_name: The name of the server. Required. + :type long_term_retention_server_name: str + :param long_term_retention_database_name: The name of the database. Required. + :type long_term_retention_database_name: str + :param backup_name: The backup name. Required. + :type backup_name: str + :param parameters: The parameters needed for long term retention copy request. Required. + :type parameters: IO + :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 + LongTermRetentionBackupOperationResult or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_copy( + self, + location_name: str, + long_term_retention_server_name: str, + long_term_retention_database_name: str, + backup_name: str, + parameters: Union[_models.CopyLongTermRetentionBackupParameters, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.LongTermRetentionBackupOperationResult]: + """Copy an existing long term retention backup. + + :param location_name: The location of the database. Required. + :type location_name: str + :param long_term_retention_server_name: The name of the server. Required. + :type long_term_retention_server_name: str + :param long_term_retention_database_name: The name of the database. Required. + :type long_term_retention_database_name: str + :param backup_name: The backup name. Required. + :type backup_name: str + :param parameters: The parameters needed for long term retention copy request. Is either a + model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.CopyLongTermRetentionBackupParameters 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 @@ -145,20 +255,17 @@ async def begin_copy( LongTermRetentionBackupOperationResult or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupOperationResult] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupOperationResult] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._copy_initial( # type: ignore location_name=location_name, @@ -168,39 +275,35 @@ async def begin_copy( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('LongTermRetentionBackupOperationResult', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackupOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_copy.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy"} # type: ignore + begin_copy.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy"} # type: ignore async def _update_initial( self, @@ -208,24 +311,28 @@ async def _update_initial( long_term_retention_server_name: str, long_term_retention_database_name: str, backup_name: str, - parameters: _models.UpdateLongTermRetentionBackupParameters, + parameters: Union[_models.UpdateLongTermRetentionBackupParameters, IO], **kwargs: Any ) -> Optional[_models.LongTermRetentionBackupOperationResult]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.LongTermRetentionBackupOperationResult]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.LongTermRetentionBackupOperationResult]] - _json = self._serialize.body(parameters, 'UpdateLongTermRetentionBackupParameters') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "UpdateLongTermRetentionBackupParameters") - request = build_update_request_initial( + request = build_update_request( location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, long_term_retention_database_name=long_term_retention_database_name, @@ -234,7 +341,8 @@ async def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -242,10 +350,9 @@ async def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -254,17 +361,16 @@ async def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('LongTermRetentionBackupOperationResult', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackupOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update"} # type: ignore + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update"} # type: ignore - - @distributed_trace_async + @overload async def begin_update( self, location_name: str, @@ -272,23 +378,67 @@ async def begin_update( long_term_retention_database_name: str, backup_name: str, parameters: _models.UpdateLongTermRetentionBackupParameters, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.LongTermRetentionBackupOperationResult]: """Updates an existing long term retention backup. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :param parameters: The requested backup resource state. + :param parameters: The requested backup resource state. Required. :type parameters: ~azure.mgmt.sql.models.UpdateLongTermRetentionBackupParameters - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 + LongTermRetentionBackupOperationResult or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_update( + self, + location_name: str, + long_term_retention_server_name: str, + long_term_retention_database_name: str, + backup_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.LongTermRetentionBackupOperationResult]: + """Updates an existing long term retention backup. + + :param location_name: The location of the database. Required. + :type location_name: str + :param long_term_retention_server_name: The name of the server. Required. + :type long_term_retention_server_name: str + :param long_term_retention_database_name: The name of the database. Required. + :type long_term_retention_database_name: str + :param backup_name: The backup name. Required. + :type backup_name: str + :param parameters: The requested backup resource state. Required. + :type parameters: IO + :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 @@ -301,20 +451,58 @@ async def begin_update( LongTermRetentionBackupOperationResult or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_update( + self, + location_name: str, + long_term_retention_server_name: str, + long_term_retention_database_name: str, + backup_name: str, + parameters: Union[_models.UpdateLongTermRetentionBackupParameters, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.LongTermRetentionBackupOperationResult]: + """Updates an existing long term retention backup. + + :param location_name: The location of the database. Required. + :type location_name: str + :param long_term_retention_server_name: The name of the server. Required. + :type long_term_retention_server_name: str + :param long_term_retention_database_name: The name of the database. Required. + :type long_term_retention_database_name: str + :param backup_name: The backup name. Required. + :type backup_name: str + :param parameters: The requested backup resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.UpdateLongTermRetentionBackupParameters 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. + :return: An instance of AsyncLROPoller that returns either + LongTermRetentionBackupOperationResult or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupOperationResult] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupOperationResult] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._update_initial( # type: ignore location_name=location_name, @@ -324,39 +512,35 @@ async def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('LongTermRetentionBackupOperationResult', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackupOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update"} # type: ignore @distributed_trace_async async def get( @@ -369,34 +553,28 @@ async def get( ) -> _models.LongTermRetentionBackup: """Gets a long term retention backup. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: LongTermRetentionBackup, or the result of cls(response) + :return: LongTermRetentionBackup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.LongTermRetentionBackup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackup] - request = build_get_request( location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, @@ -404,7 +582,7 @@ async def get( backup_name=backup_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -412,25 +590,23 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('LongTermRetentionBackup', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements self, @@ -440,26 +616,23 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements backup_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, long_term_retention_database_name=long_term_retention_database_name, backup_name=backup_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -467,10 +640,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -480,11 +652,10 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements + async def begin_delete( self, location_name: str, long_term_retention_server_name: str, @@ -494,17 +665,14 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements ) -> AsyncLROPoller[None]: """Deletes a long term retention backup. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -515,19 +683,16 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore location_name=location_name, @@ -535,37 +700,33 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements long_term_retention_database_name=long_term_retention_database_name, backup_name=backup_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore @distributed_trace def list_by_database( @@ -576,53 +737,48 @@ def list_by_database( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> AsyncIterable[_models.LongTermRetentionBackupListResult]: + ) -> AsyncIterable["_models.LongTermRetentionBackup"]: """Lists all long term retention backups for a database. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LongTermRetentionBackupListResult or the result of + :return: An iterator like instance of either LongTermRetentionBackup or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, long_term_retention_database_name=long_term_retention_database_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -630,19 +786,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - location_name=location_name, - long_term_retention_server_name=long_term_retention_server_name, - long_term_retention_database_name=long_term_retention_database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -658,10 +802,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -671,11 +813,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups"} # type: ignore @distributed_trace def list_by_location( @@ -684,47 +824,42 @@ def list_by_location( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> AsyncIterable[_models.LongTermRetentionBackupListResult]: + ) -> AsyncIterable["_models.LongTermRetentionBackup"]: """Lists the long term retention backups for a given location. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LongTermRetentionBackupListResult or the result of + :return: An iterator like instance of either LongTermRetentionBackup or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_location_request( location_name=location_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_location.metadata['url'], + api_version=api_version, + template_url=self.list_by_location.metadata["url"], headers=_headers, params=_params, ) @@ -732,17 +867,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_location_request( - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -758,10 +883,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -771,11 +894,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionBackups"} # type: ignore + list_by_location.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionBackups"} # type: ignore @distributed_trace def list_by_server( @@ -785,50 +906,45 @@ def list_by_server( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> AsyncIterable[_models.LongTermRetentionBackupListResult]: + ) -> AsyncIterable["_models.LongTermRetentionBackup"]: """Lists the long term retention backups for a given server. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LongTermRetentionBackupListResult or the result of + :return: An iterator like instance of either LongTermRetentionBackup or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_server.metadata['url'], + api_version=api_version, + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -836,18 +952,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - location_name=location_name, - long_term_retention_server_name=long_term_retention_server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -863,10 +968,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -876,11 +979,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionBackups"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionBackups"} # type: ignore async def _copy_by_resource_group_initial( self, @@ -889,24 +990,28 @@ async def _copy_by_resource_group_initial( long_term_retention_server_name: str, long_term_retention_database_name: str, backup_name: str, - parameters: _models.CopyLongTermRetentionBackupParameters, + parameters: Union[_models.CopyLongTermRetentionBackupParameters, IO], **kwargs: Any ) -> Optional[_models.LongTermRetentionBackupOperationResult]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.LongTermRetentionBackupOperationResult]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.LongTermRetentionBackupOperationResult]] - _json = self._serialize.body(parameters, 'CopyLongTermRetentionBackupParameters') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "CopyLongTermRetentionBackupParameters") - request = build_copy_by_resource_group_request_initial( + request = build_copy_by_resource_group_request( resource_group_name=resource_group_name, location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, @@ -916,7 +1021,8 @@ async def _copy_by_resource_group_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._copy_by_resource_group_initial.metadata['url'], + content=_content, + template_url=self._copy_by_resource_group_initial.metadata["url"], headers=_headers, params=_params, ) @@ -924,10 +1030,9 @@ async def _copy_by_resource_group_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -936,17 +1041,16 @@ async def _copy_by_resource_group_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('LongTermRetentionBackupOperationResult', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackupOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _copy_by_resource_group_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy"} # type: ignore - + _copy_by_resource_group_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy"} # type: ignore - @distributed_trace_async + @overload async def begin_copy_by_resource_group( self, resource_group_name: str, @@ -955,26 +1059,28 @@ async def begin_copy_by_resource_group( long_term_retention_database_name: str, backup_name: str, parameters: _models.CopyLongTermRetentionBackupParameters, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.LongTermRetentionBackupOperationResult]: """Copy an existing long term retention backup to a different server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :param parameters: The parameters needed for long term retention copy request. + :param parameters: The parameters needed for long term retention copy request. Required. :type parameters: ~azure.mgmt.sql.models.CopyLongTermRetentionBackupParameters - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -987,20 +1093,108 @@ async def begin_copy_by_resource_group( LongTermRetentionBackupOperationResult or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_copy_by_resource_group( + self, + resource_group_name: str, + location_name: str, + long_term_retention_server_name: str, + long_term_retention_database_name: str, + backup_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.LongTermRetentionBackupOperationResult]: + """Copy an existing long term retention backup to a different server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param location_name: The location of the database. Required. + :type location_name: str + :param long_term_retention_server_name: The name of the server. Required. + :type long_term_retention_server_name: str + :param long_term_retention_database_name: The name of the database. Required. + :type long_term_retention_database_name: str + :param backup_name: The backup name. Required. + :type backup_name: str + :param parameters: The parameters needed for long term retention copy request. Required. + :type parameters: IO + :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 + LongTermRetentionBackupOperationResult or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_copy_by_resource_group( + self, + resource_group_name: str, + location_name: str, + long_term_retention_server_name: str, + long_term_retention_database_name: str, + backup_name: str, + parameters: Union[_models.CopyLongTermRetentionBackupParameters, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.LongTermRetentionBackupOperationResult]: + """Copy an existing long term retention backup to a different server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param location_name: The location of the database. Required. + :type location_name: str + :param long_term_retention_server_name: The name of the server. Required. + :type long_term_retention_server_name: str + :param long_term_retention_database_name: The name of the database. Required. + :type long_term_retention_database_name: str + :param backup_name: The backup name. Required. + :type backup_name: str + :param parameters: The parameters needed for long term retention copy request. Is either a + model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.CopyLongTermRetentionBackupParameters 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. + :return: An instance of AsyncLROPoller that returns either + LongTermRetentionBackupOperationResult or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupOperationResult] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupOperationResult] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._copy_by_resource_group_initial( # type: ignore resource_group_name=resource_group_name, @@ -1011,39 +1205,35 @@ async def begin_copy_by_resource_group( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('LongTermRetentionBackupOperationResult', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackupOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_copy_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy"} # type: ignore + begin_copy_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy"} # type: ignore async def _update_by_resource_group_initial( self, @@ -1052,24 +1242,28 @@ async def _update_by_resource_group_initial( long_term_retention_server_name: str, long_term_retention_database_name: str, backup_name: str, - parameters: _models.UpdateLongTermRetentionBackupParameters, + parameters: Union[_models.UpdateLongTermRetentionBackupParameters, IO], **kwargs: Any ) -> Optional[_models.LongTermRetentionBackupOperationResult]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.LongTermRetentionBackupOperationResult]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.LongTermRetentionBackupOperationResult]] - _json = self._serialize.body(parameters, 'UpdateLongTermRetentionBackupParameters') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "UpdateLongTermRetentionBackupParameters") - request = build_update_by_resource_group_request_initial( + request = build_update_by_resource_group_request( resource_group_name=resource_group_name, location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, @@ -1079,7 +1273,8 @@ async def _update_by_resource_group_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_by_resource_group_initial.metadata['url'], + content=_content, + template_url=self._update_by_resource_group_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1087,10 +1282,9 @@ async def _update_by_resource_group_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1099,17 +1293,16 @@ async def _update_by_resource_group_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('LongTermRetentionBackupOperationResult', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackupOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_by_resource_group_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update"} # type: ignore + _update_by_resource_group_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update"} # type: ignore - - @distributed_trace_async + @overload async def begin_update_by_resource_group( self, resource_group_name: str, @@ -1118,26 +1311,74 @@ async def begin_update_by_resource_group( long_term_retention_database_name: str, backup_name: str, parameters: _models.UpdateLongTermRetentionBackupParameters, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.LongTermRetentionBackupOperationResult]: """Updates an existing long term retention backup. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :param parameters: The requested backup resource state. + :param parameters: The requested backup resource state. Required. :type parameters: ~azure.mgmt.sql.models.UpdateLongTermRetentionBackupParameters - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 + LongTermRetentionBackupOperationResult or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_update_by_resource_group( + self, + resource_group_name: str, + location_name: str, + long_term_retention_server_name: str, + long_term_retention_database_name: str, + backup_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.LongTermRetentionBackupOperationResult]: + """Updates an existing long term retention backup. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param location_name: The location of the database. Required. + :type location_name: str + :param long_term_retention_server_name: The name of the server. Required. + :type long_term_retention_server_name: str + :param long_term_retention_database_name: The name of the database. Required. + :type long_term_retention_database_name: str + :param backup_name: The backup name. Required. + :type backup_name: str + :param parameters: The requested backup resource state. Required. + :type parameters: IO + :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 @@ -1150,20 +1391,62 @@ async def begin_update_by_resource_group( LongTermRetentionBackupOperationResult or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_update_by_resource_group( + self, + resource_group_name: str, + location_name: str, + long_term_retention_server_name: str, + long_term_retention_database_name: str, + backup_name: str, + parameters: Union[_models.UpdateLongTermRetentionBackupParameters, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.LongTermRetentionBackupOperationResult]: + """Updates an existing long term retention backup. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param location_name: The location of the database. Required. + :type location_name: str + :param long_term_retention_server_name: The name of the server. Required. + :type long_term_retention_server_name: str + :param long_term_retention_database_name: The name of the database. Required. + :type long_term_retention_database_name: str + :param backup_name: The backup name. Required. + :type backup_name: str + :param parameters: The requested backup resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.UpdateLongTermRetentionBackupParameters 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. + :return: An instance of AsyncLROPoller that returns either + LongTermRetentionBackupOperationResult or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupOperationResult] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupOperationResult] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._update_by_resource_group_initial( # type: ignore resource_group_name=resource_group_name, @@ -1174,39 +1457,35 @@ async def begin_update_by_resource_group( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('LongTermRetentionBackupOperationResult', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackupOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update"} # type: ignore + begin_update_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update"} # type: ignore @distributed_trace_async async def get_by_resource_group( @@ -1221,36 +1500,30 @@ async def get_by_resource_group( """Gets a long term retention backup. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: LongTermRetentionBackup, or the result of cls(response) + :return: LongTermRetentionBackup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.LongTermRetentionBackup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackup] - request = build_get_by_resource_group_request( resource_group_name=resource_group_name, location_name=location_name, @@ -1259,7 +1532,7 @@ async def get_by_resource_group( backup_name=backup_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get_by_resource_group.metadata['url'], + template_url=self.get_by_resource_group.metadata["url"], headers=_headers, params=_params, ) @@ -1267,25 +1540,23 @@ async def get_by_resource_group( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('LongTermRetentionBackup', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore - + get_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore async def _delete_by_resource_group_initial( # pylint: disable=inconsistent-return-statements self, @@ -1296,19 +1567,16 @@ async def _delete_by_resource_group_initial( # pylint: disable=inconsistent-ret backup_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_by_resource_group_request_initial( + request = build_delete_by_resource_group_request( resource_group_name=resource_group_name, location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, @@ -1316,7 +1584,7 @@ async def _delete_by_resource_group_initial( # pylint: disable=inconsistent-ret backup_name=backup_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_by_resource_group_initial.metadata['url'], + template_url=self._delete_by_resource_group_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1324,10 +1592,9 @@ async def _delete_by_resource_group_initial( # pylint: disable=inconsistent-ret request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1337,11 +1604,10 @@ async def _delete_by_resource_group_initial( # pylint: disable=inconsistent-ret if cls: return cls(pipeline_response, None, {}) - _delete_by_resource_group_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore - + _delete_by_resource_group_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore @distributed_trace_async - async def begin_delete_by_resource_group( # pylint: disable=inconsistent-return-statements + async def begin_delete_by_resource_group( self, resource_group_name: str, location_name: str, @@ -1353,19 +1619,16 @@ async def begin_delete_by_resource_group( # pylint: disable=inconsistent-return """Deletes a long term retention backup. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1376,19 +1639,16 @@ async def begin_delete_by_resource_group( # pylint: disable=inconsistent-return 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_by_resource_group_initial( # type: ignore resource_group_name=resource_group_name, @@ -1397,37 +1657,33 @@ async def begin_delete_by_resource_group( # pylint: disable=inconsistent-return long_term_retention_database_name=long_term_retention_database_name, backup_name=backup_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_delete_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore + begin_delete_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore @distributed_trace def list_by_resource_group_database( @@ -1439,57 +1695,52 @@ def list_by_resource_group_database( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> AsyncIterable[_models.LongTermRetentionBackupListResult]: + ) -> AsyncIterable["_models.LongTermRetentionBackup"]: """Lists all long term retention backups for a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LongTermRetentionBackupListResult or the result of + :return: An iterator like instance of either LongTermRetentionBackup or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_database_request( resource_group_name=resource_group_name, location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, long_term_retention_database_name=long_term_retention_database_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_resource_group_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_resource_group_database.metadata["url"], headers=_headers, params=_params, ) @@ -1497,20 +1748,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_database_request( - resource_group_name=resource_group_name, - location_name=location_name, - long_term_retention_server_name=long_term_retention_server_name, - long_term_retention_database_name=long_term_retention_database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1526,10 +1764,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1539,11 +1775,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_resource_group_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups"} # type: ignore + list_by_resource_group_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups"} # type: ignore @distributed_trace def list_by_resource_group_location( @@ -1553,51 +1787,46 @@ def list_by_resource_group_location( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> AsyncIterable[_models.LongTermRetentionBackupListResult]: + ) -> AsyncIterable["_models.LongTermRetentionBackup"]: """Lists the long term retention backups for a given location. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LongTermRetentionBackupListResult or the result of + :return: An iterator like instance of either LongTermRetentionBackup or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_location_request( resource_group_name=resource_group_name, location_name=location_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_resource_group_location.metadata['url'], + api_version=api_version, + template_url=self.list_by_resource_group_location.metadata["url"], headers=_headers, params=_params, ) @@ -1605,18 +1834,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_location_request( - resource_group_name=resource_group_name, - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1632,10 +1850,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1645,11 +1861,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_resource_group_location.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionBackups"} # type: ignore + list_by_resource_group_location.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionBackups"} # type: ignore @distributed_trace def list_by_resource_group_server( @@ -1660,54 +1874,49 @@ def list_by_resource_group_server( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> AsyncIterable[_models.LongTermRetentionBackupListResult]: + ) -> AsyncIterable["_models.LongTermRetentionBackup"]: """Lists the long term retention backups for a given server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LongTermRetentionBackupListResult or the result of + :return: An iterator like instance of either LongTermRetentionBackup or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_server_request( resource_group_name=resource_group_name, location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_resource_group_server.metadata['url'], + api_version=api_version, + template_url=self.list_by_resource_group_server.metadata["url"], headers=_headers, params=_params, ) @@ -1715,19 +1924,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_server_request( - resource_group_name=resource_group_name, - location_name=location_name, - long_term_retention_server_name=long_term_retention_server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1743,10 +1940,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1756,8 +1951,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_resource_group_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionBackups"} # type: ignore + list_by_resource_group_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionBackups"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_long_term_retention_managed_instance_backups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_long_term_retention_managed_instance_backups_operations.py index 0751ca9cdd959..797b9f9b0fd37 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_long_term_retention_managed_instance_backups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_long_term_retention_managed_instance_backups_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,23 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._long_term_retention_managed_instance_backups_operations import build_delete_by_resource_group_request_initial, build_delete_request_initial, build_get_by_resource_group_request, build_get_request, build_list_by_database_request, build_list_by_instance_request, build_list_by_location_request, build_list_by_resource_group_database_request, build_list_by_resource_group_instance_request, build_list_by_resource_group_location_request -T = TypeVar('T') +from ...operations._long_term_retention_managed_instance_backups_operations import ( + build_delete_by_resource_group_request, + build_delete_request, + build_get_by_resource_group_request, + build_get_request, + build_list_by_database_request, + build_list_by_instance_request, + build_list_by_location_request, + build_list_by_resource_group_database_request, + build_list_by_resource_group_instance_request, + build_list_by_resource_group_location_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class LongTermRetentionManagedInstanceBackupsOperations: """ .. warning:: @@ -45,46 +64,34 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - location_name: str, - managed_instance_name: str, - database_name: str, - backup_name: str, - **kwargs: Any + self, location_name: str, managed_instance_name: str, database_name: str, backup_name: str, **kwargs: Any ) -> _models.ManagedInstanceLongTermRetentionBackup: """Gets a long term retention backup for a managed database. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the managed database. + :param database_name: The name of the managed database. Required. :type database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceLongTermRetentionBackup, or the result of cls(response) + :return: ManagedInstanceLongTermRetentionBackup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackup] - request = build_get_request( location_name=location_name, managed_instance_name=managed_instance_name, @@ -92,7 +99,7 @@ async def get( backup_name=backup_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -100,54 +107,44 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceLongTermRetentionBackup', pipeline_response) + deserialized = self._deserialize("ManagedInstanceLongTermRetentionBackup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - location_name: str, - managed_instance_name: str, - database_name: str, - backup_name: str, - **kwargs: Any + self, location_name: str, managed_instance_name: str, database_name: str, backup_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( location_name=location_name, managed_instance_name=managed_instance_name, database_name=database_name, backup_name=backup_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -155,10 +152,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -168,31 +164,22 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - location_name: str, - managed_instance_name: str, - database_name: str, - backup_name: str, - **kwargs: Any + async def begin_delete( + self, location_name: str, managed_instance_name: str, database_name: str, backup_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes a long term retention backup. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the managed database. + :param database_name: The name of the managed database. Required. :type database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -203,19 +190,16 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore location_name=location_name, @@ -223,37 +207,33 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements database_name=database_name, backup_name=backup_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore @distributed_trace def list_by_database( @@ -264,53 +244,49 @@ def list_by_database( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstanceLongTermRetentionBackupListResult]: + ) -> AsyncIterable["_models.ManagedInstanceLongTermRetentionBackup"]: """Lists all long term retention backups for a managed database. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the managed database. + :param database_name: The name of the managed database. Required. :type database_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackupListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackup or the + result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( location_name=location_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -318,19 +294,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - location_name=location_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -346,10 +310,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -359,11 +321,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups"} # type: ignore @distributed_trace def list_by_instance( @@ -373,50 +333,46 @@ def list_by_instance( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstanceLongTermRetentionBackupListResult]: + ) -> AsyncIterable["_models.ManagedInstanceLongTermRetentionBackup"]: """Lists the long term retention backups for a given managed instance. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackupListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackup or the + result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( location_name=location_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_instance.metadata['url'], + api_version=api_version, + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -424,18 +380,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - location_name=location_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -451,10 +396,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -464,11 +407,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionManagedInstanceBackups"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionManagedInstanceBackups"} # type: ignore @distributed_trace def list_by_location( @@ -477,47 +418,43 @@ def list_by_location( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstanceLongTermRetentionBackupListResult]: + ) -> AsyncIterable["_models.ManagedInstanceLongTermRetentionBackup"]: """Lists the long term retention backups for managed databases in a given location. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackupListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackup or the + result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_location_request( location_name=location_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_location.metadata['url'], + api_version=api_version, + template_url=self.list_by_location.metadata["url"], headers=_headers, params=_params, ) @@ -525,17 +462,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_location_request( - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -551,10 +478,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -564,11 +489,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstanceBackups"} # type: ignore + list_by_location.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstanceBackups"} # type: ignore @distributed_trace_async async def get_by_resource_group( @@ -583,36 +506,30 @@ async def get_by_resource_group( """Gets a long term retention backup for a managed database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the managed database. + :param database_name: The name of the managed database. Required. :type database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceLongTermRetentionBackup, or the result of cls(response) + :return: ManagedInstanceLongTermRetentionBackup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackup] - request = build_get_by_resource_group_request( resource_group_name=resource_group_name, location_name=location_name, @@ -621,7 +538,7 @@ async def get_by_resource_group( backup_name=backup_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get_by_resource_group.metadata['url'], + template_url=self.get_by_resource_group.metadata["url"], headers=_headers, params=_params, ) @@ -629,25 +546,23 @@ async def get_by_resource_group( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceLongTermRetentionBackup', pipeline_response) + deserialized = self._deserialize("ManagedInstanceLongTermRetentionBackup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore - + get_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore async def _delete_by_resource_group_initial( # pylint: disable=inconsistent-return-statements self, @@ -658,19 +573,16 @@ async def _delete_by_resource_group_initial( # pylint: disable=inconsistent-ret backup_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_by_resource_group_request_initial( + request = build_delete_by_resource_group_request( resource_group_name=resource_group_name, location_name=location_name, managed_instance_name=managed_instance_name, @@ -678,7 +590,7 @@ async def _delete_by_resource_group_initial( # pylint: disable=inconsistent-ret backup_name=backup_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_by_resource_group_initial.metadata['url'], + template_url=self._delete_by_resource_group_initial.metadata["url"], headers=_headers, params=_params, ) @@ -686,10 +598,9 @@ async def _delete_by_resource_group_initial( # pylint: disable=inconsistent-ret request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -699,11 +610,10 @@ async def _delete_by_resource_group_initial( # pylint: disable=inconsistent-ret if cls: return cls(pipeline_response, None, {}) - _delete_by_resource_group_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore - + _delete_by_resource_group_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore @distributed_trace_async - async def begin_delete_by_resource_group( # pylint: disable=inconsistent-return-statements + async def begin_delete_by_resource_group( self, resource_group_name: str, location_name: str, @@ -715,19 +625,16 @@ async def begin_delete_by_resource_group( # pylint: disable=inconsistent-return """Deletes a long term retention backup. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the managed database. + :param database_name: The name of the managed database. Required. :type database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -738,19 +645,16 @@ async def begin_delete_by_resource_group( # pylint: disable=inconsistent-return 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_by_resource_group_initial( # type: ignore resource_group_name=resource_group_name, @@ -759,37 +663,33 @@ async def begin_delete_by_resource_group( # pylint: disable=inconsistent-return database_name=database_name, backup_name=backup_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_delete_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore + begin_delete_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore @distributed_trace def list_by_resource_group_database( @@ -801,57 +701,53 @@ def list_by_resource_group_database( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstanceLongTermRetentionBackupListResult]: + ) -> AsyncIterable["_models.ManagedInstanceLongTermRetentionBackup"]: """Lists all long term retention backups for a managed database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the managed database. + :param database_name: The name of the managed database. Required. :type database_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackupListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackup or the + result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_database_request( resource_group_name=resource_group_name, location_name=location_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_resource_group_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_resource_group_database.metadata["url"], headers=_headers, params=_params, ) @@ -859,20 +755,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_database_request( - resource_group_name=resource_group_name, - location_name=location_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -888,10 +771,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -901,11 +782,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_resource_group_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups"} # type: ignore + list_by_resource_group_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups"} # type: ignore @distributed_trace def list_by_resource_group_instance( @@ -916,54 +795,50 @@ def list_by_resource_group_instance( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstanceLongTermRetentionBackupListResult]: + ) -> AsyncIterable["_models.ManagedInstanceLongTermRetentionBackup"]: """Lists the long term retention backups for a given managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackupListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackup or the + result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_instance_request( resource_group_name=resource_group_name, location_name=location_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_resource_group_instance.metadata['url'], + api_version=api_version, + template_url=self.list_by_resource_group_instance.metadata["url"], headers=_headers, params=_params, ) @@ -971,19 +846,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_instance_request( - resource_group_name=resource_group_name, - location_name=location_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -999,10 +862,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1012,11 +873,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_resource_group_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionManagedInstanceBackups"} # type: ignore + list_by_resource_group_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionManagedInstanceBackups"} # type: ignore @distributed_trace def list_by_resource_group_location( @@ -1026,51 +885,47 @@ def list_by_resource_group_location( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstanceLongTermRetentionBackupListResult]: + ) -> AsyncIterable["_models.ManagedInstanceLongTermRetentionBackup"]: """Lists the long term retention backups for managed databases in a given location. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackupListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackup or the + result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_location_request( resource_group_name=resource_group_name, location_name=location_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_resource_group_location.metadata['url'], + api_version=api_version, + template_url=self.list_by_resource_group_location.metadata["url"], headers=_headers, params=_params, ) @@ -1078,18 +933,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_location_request( - resource_group_name=resource_group_name, - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1105,10 +949,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1118,8 +960,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_resource_group_location.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstanceBackups"} # type: ignore + list_by_resource_group_location.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstanceBackups"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_long_term_retention_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_long_term_retention_policies_operations.py index eb38639d903be..127f32a06b245 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_long_term_retention_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_long_term_retention_policies_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._long_term_retention_policies_operations import build_create_or_update_request_initial, build_get_request, build_list_by_database_request -T = TypeVar('T') +from ...operations._long_term_retention_policies_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class LongTermRetentionPoliciesOperations: """ .. warning:: @@ -45,7 +57,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -58,34 +69,28 @@ async def get( """Gets a database's long term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be Default. + :param policy_name: The policy name. Should always be Default. "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.LongTermRetentionPolicyName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: LongTermRetentionPolicy, or the result of cls(response) + :return: LongTermRetentionPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.LongTermRetentionPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -93,7 +98,7 @@ async def get( policy_name=policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -101,25 +106,23 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('LongTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("LongTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore async def _create_or_update_initial( self, @@ -127,24 +130,28 @@ async def _create_or_update_initial( server_name: str, database_name: str, policy_name: Union[str, "_models.LongTermRetentionPolicyName"], - parameters: _models.LongTermRetentionPolicy, + parameters: Union[_models.LongTermRetentionPolicy, IO], **kwargs: Any ) -> Optional[_models.LongTermRetentionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.LongTermRetentionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.LongTermRetentionPolicy]] - _json = self._serialize.body(parameters, 'LongTermRetentionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "LongTermRetentionPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -153,7 +160,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -161,10 +169,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -173,17 +180,16 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('LongTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("LongTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, @@ -191,24 +197,68 @@ async def begin_create_or_update( database_name: str, policy_name: Union[str, "_models.LongTermRetentionPolicyName"], parameters: _models.LongTermRetentionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.LongTermRetentionPolicy]: """Sets a database's long term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be Default. + :param policy_name: The policy name. Should always be Default. "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.LongTermRetentionPolicyName - :param parameters: The long term retention policy info. + :param parameters: The long term retention policy info. Required. :type parameters: ~azure.mgmt.sql.models.LongTermRetentionPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 LongTermRetentionPolicy or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LongTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + policy_name: Union[str, "_models.LongTermRetentionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.LongTermRetentionPolicy]: + """Sets a database's long term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be Default. "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.LongTermRetentionPolicyName + :param parameters: The long term retention policy info. Required. + :type parameters: IO + :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 @@ -220,20 +270,58 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either LongTermRetentionPolicy or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LongTermRetentionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + policy_name: Union[str, "_models.LongTermRetentionPolicyName"], + parameters: Union[_models.LongTermRetentionPolicy, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.LongTermRetentionPolicy]: + """Sets a database's long term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be Default. "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.LongTermRetentionPolicyName + :param parameters: The long term retention policy info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.LongTermRetentionPolicy 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. + :return: An instance of AsyncLROPoller that returns either LongTermRetentionPolicy or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.LongTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -243,87 +331,74 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('LongTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("LongTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.LongTermRetentionPolicyListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.LongTermRetentionPolicy"]: """Gets a database's long term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LongTermRetentionPolicyListResult or the result of + :return: An iterator like instance of either LongTermRetentionPolicy or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LongTermRetentionPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LongTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -331,17 +406,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -357,10 +422,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -370,8 +433,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_maintenance_window_options_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_maintenance_window_options_operations.py index da57246403a05..462b2914c1745 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_maintenance_window_options_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_maintenance_window_options_operations.py @@ -8,7 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Optional, TypeVar -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -19,9 +25,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._maintenance_window_options_operations import build_get_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class MaintenanceWindowOptionsOperations: """ .. warning:: @@ -41,7 +49,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -54,42 +61,37 @@ async def get( """Gets a list of available maintenance windows. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database to get maintenance windows options for. + Required. :type database_name: str - :param maintenance_window_options_name: Maintenance window options name. + :param maintenance_window_options_name: Maintenance window options name. Required. :type maintenance_window_options_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: MaintenanceWindowOptions, or the result of cls(response) + :return: MaintenanceWindowOptions or the result of cls(response) :rtype: ~azure.mgmt.sql.models.MaintenanceWindowOptions - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.MaintenanceWindowOptions] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.MaintenanceWindowOptions] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, maintenance_window_options_name=maintenance_window_options_name, - template_url=self.get.metadata['url'], + api_version=api_version, + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,22 +99,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('MaintenanceWindowOptions', pipeline_response) + deserialized = self._deserialize("MaintenanceWindowOptions", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindowOptions/current"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindowOptions/current"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_maintenance_windows_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_maintenance_windows_operations.py index 947246976cba8..08a0f1413392e 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_maintenance_windows_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_maintenance_windows_operations.py @@ -6,9 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -19,9 +25,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._maintenance_windows_operations import build_create_or_update_request, build_get_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class MaintenanceWindowsOperations: """ .. warning:: @@ -41,7 +49,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -54,42 +61,36 @@ async def get( """Gets maintenance windows settings for a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database to get maintenance windows for. + :param database_name: The name of the database to get maintenance windows for. Required. :type database_name: str - :param maintenance_window_name: Maintenance window name. + :param maintenance_window_name: Maintenance window name. Required. :type maintenance_window_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: MaintenanceWindows, or the result of cls(response) + :return: MaintenanceWindows or the result of cls(response) :rtype: ~azure.mgmt.sql.models.MaintenanceWindows - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.MaintenanceWindows] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.MaintenanceWindows] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, maintenance_window_name=maintenance_window_name, - template_url=self.get.metadata['url'], + api_version=api_version, + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,27 +98,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('MaintenanceWindows', pipeline_response) + deserialized = self._deserialize("MaintenanceWindows", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindows/current"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindows/current"} # type: ignore - @distributed_trace_async + @overload async def create_or_update( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, @@ -125,53 +124,126 @@ async def create_or_update( # pylint: disable=inconsistent-return-statements database_name: str, maintenance_window_name: str, parameters: _models.MaintenanceWindows, + *, + content_type: str = "application/json", **kwargs: Any ) -> None: """Sets maintenance windows settings for a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database to set maintenance windows for. + :param database_name: The name of the database to set maintenance windows for. Required. :type database_name: str - :param maintenance_window_name: Maintenance window name. + :param maintenance_window_name: Maintenance window name. Required. :type maintenance_window_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.MaintenanceWindows - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def create_or_update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + server_name: str, + database_name: str, + maintenance_window_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> None: + """Sets maintenance windows settings for a database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database to set maintenance windows for. Required. + :type database_name: str + :param maintenance_window_name: Maintenance window name. Required. + :type maintenance_window_name: str + :param parameters: Required. + :type parameters: IO + :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: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + server_name: str, + database_name: str, + maintenance_window_name: str, + parameters: Union[_models.MaintenanceWindows, IO], + **kwargs: Any + ) -> None: + """Sets maintenance windows settings for a database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database to set maintenance windows for. Required. + :type database_name: str + :param maintenance_window_name: Maintenance window name. Required. + :type maintenance_window_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.MaintenanceWindows 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 + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'MaintenanceWindows') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "MaintenanceWindows") request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, + maintenance_window_name=maintenance_window_name, api_version=api_version, content_type=content_type, - maintenance_window_name=maintenance_window_name, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -179,10 +251,9 @@ async def create_or_update( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -192,5 +263,4 @@ async def create_or_update( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindows/current"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindows/current"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_backup_short_term_retention_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_backup_short_term_retention_policies_operations.py index 1bc381888fbb3..2a039a0ff634f 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_backup_short_term_retention_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_backup_short_term_retention_policies_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_backup_short_term_retention_policies_operations import build_create_or_update_request_initial, build_get_request, build_list_by_database_request, build_update_request_initial -T = TypeVar('T') +from ...operations._managed_backup_short_term_retention_policies_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_database_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedBackupShortTermRetentionPoliciesOperations: """ .. warning:: @@ -45,7 +58,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -58,34 +70,28 @@ async def get( """Gets a managed database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. + :param policy_name: The policy name. "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedBackupShortTermRetentionPolicy, or the result of cls(response) + :return: ManagedBackupShortTermRetentionPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -93,7 +99,7 @@ async def get( policy_name=policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -101,25 +107,23 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore async def _create_or_update_initial( self, @@ -127,24 +131,28 @@ async def _create_or_update_initial( managed_instance_name: str, database_name: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], - parameters: _models.ManagedBackupShortTermRetentionPolicy, + parameters: Union[_models.ManagedBackupShortTermRetentionPolicy, IO], **kwargs: Any ) -> Optional[_models.ManagedBackupShortTermRetentionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedBackupShortTermRetentionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedBackupShortTermRetentionPolicy]] - _json = self._serialize.body(parameters, 'ManagedBackupShortTermRetentionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedBackupShortTermRetentionPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, @@ -153,7 +161,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -161,10 +170,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -173,17 +181,16 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, @@ -191,24 +198,26 @@ async def begin_create_or_update( database_name: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], parameters: _models.ManagedBackupShortTermRetentionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ManagedBackupShortTermRetentionPolicy]: """Updates a managed database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be "default". + :param policy_name: The policy name. Should always be "default". "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName - :param parameters: The short term retention policy info. + :param parameters: The short term retention policy info. Required. :type parameters: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -221,20 +230,102 @@ async def begin_create_or_update( ManagedBackupShortTermRetentionPolicy or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedBackupShortTermRetentionPolicy]: + """Updates a managed database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Required. + :type parameters: IO + :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 + ManagedBackupShortTermRetentionPolicy or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], + parameters: Union[_models.ManagedBackupShortTermRetentionPolicy, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedBackupShortTermRetentionPolicy]: + """Updates a managed database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy 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. + :return: An instance of AsyncLROPoller that returns either + ManagedBackupShortTermRetentionPolicy or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -244,39 +335,35 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore async def _update_initial( self, @@ -284,24 +371,28 @@ async def _update_initial( managed_instance_name: str, database_name: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], - parameters: _models.ManagedBackupShortTermRetentionPolicy, + parameters: Union[_models.ManagedBackupShortTermRetentionPolicy, IO], **kwargs: Any ) -> Optional[_models.ManagedBackupShortTermRetentionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedBackupShortTermRetentionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedBackupShortTermRetentionPolicy]] - _json = self._serialize.body(parameters, 'ManagedBackupShortTermRetentionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedBackupShortTermRetentionPolicy") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, @@ -310,7 +401,8 @@ async def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -318,10 +410,9 @@ async def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -330,17 +421,16 @@ async def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - @distributed_trace_async + @overload async def begin_update( self, resource_group_name: str, @@ -348,24 +438,69 @@ async def begin_update( database_name: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], parameters: _models.ManagedBackupShortTermRetentionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ManagedBackupShortTermRetentionPolicy]: """Updates a managed database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be "default". + :param policy_name: The policy name. Should always be "default". "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName - :param parameters: The short term retention policy info. + :param parameters: The short term retention policy info. Required. :type parameters: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 + ManagedBackupShortTermRetentionPolicy or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedBackupShortTermRetentionPolicy]: + """Updates a managed database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Required. + :type parameters: IO + :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 @@ -378,20 +513,59 @@ async def begin_update( ManagedBackupShortTermRetentionPolicy or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], + parameters: Union[_models.ManagedBackupShortTermRetentionPolicy, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedBackupShortTermRetentionPolicy]: + """Updates a managed database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy 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. + :return: An instance of AsyncLROPoller that returns either + ManagedBackupShortTermRetentionPolicy or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -401,87 +575,75 @@ async def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedBackupShortTermRetentionPolicyListResult]: + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedBackupShortTermRetentionPolicy"]: """Gets a managed database's short term retention policy list. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedBackupShortTermRetentionPolicyListResult or - the result of cls(response) + :return: An iterator like instance of either ManagedBackupShortTermRetentionPolicy or the + result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -489,17 +651,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -515,10 +667,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -528,8 +678,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_advanced_threat_protection_settings_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_advanced_threat_protection_settings_operations.py new file mode 100644 index 0000000000000..f5c7f57689c01 --- /dev/null +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_advanced_threat_protection_settings_operations.py @@ -0,0 +1,366 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.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._managed_database_advanced_threat_protection_settings_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_database_request, +) + +T = TypeVar("T") +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + + +class ManagedDatabaseAdvancedThreatProtectionSettingsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.mgmt.sql.aio.SqlManagementClient`'s + :attr:`managed_database_advanced_threat_protection_settings` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs) -> None: + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace + def list_by_database( + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedDatabaseAdvancedThreatProtection"]: + """Gets a list of managed database's Advanced Threat Protection states. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ManagedDatabaseAdvancedThreatProtection or the + result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedDatabaseAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _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: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseAdvancedThreatProtectionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_database_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_database.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + else: + request = HttpRequest("GET", next_link) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("ManagedDatabaseAdvancedThreatProtectionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/advancedThreatProtectionSettings"} # type: ignore + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + **kwargs: Any + ) -> _models.ManagedDatabaseAdvancedThreatProtection: + """Gets a managed database's Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ManagedDatabaseAdvancedThreatProtection or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedDatabaseAdvancedThreatProtection + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + _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: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseAdvancedThreatProtection] + + request = build_get_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + advanced_threat_protection_name=advanced_threat_protection_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 + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("ManagedDatabaseAdvancedThreatProtection", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore + + @overload + async def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: _models.ManagedDatabaseAdvancedThreatProtection, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.ManagedDatabaseAdvancedThreatProtection: + """Creates or updates a managed database's Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The managed database Advanced Threat Protection state. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseAdvancedThreatProtection + :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: ManagedDatabaseAdvancedThreatProtection or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedDatabaseAdvancedThreatProtection + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.ManagedDatabaseAdvancedThreatProtection: + """Creates or updates a managed database's Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The managed database Advanced Threat Protection state. Required. + :type parameters: IO + :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: ManagedDatabaseAdvancedThreatProtection or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedDatabaseAdvancedThreatProtection + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: Union[_models.ManagedDatabaseAdvancedThreatProtection, IO], + **kwargs: Any + ) -> _models.ManagedDatabaseAdvancedThreatProtection: + """Creates or updates a managed database's Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The managed database Advanced Threat Protection state. Is either a model + type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseAdvancedThreatProtection 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 + :return: ManagedDatabaseAdvancedThreatProtection or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedDatabaseAdvancedThreatProtection + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_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: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseAdvancedThreatProtection] + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedDatabaseAdvancedThreatProtection") + + request = build_create_or_update_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + advanced_threat_protection_name=advanced_threat_protection_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + 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 + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + 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("ManagedDatabaseAdvancedThreatProtection", pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize("ManagedDatabaseAdvancedThreatProtection", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_columns_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_columns_operations.py index dd67464c7aa46..5b9950e2d06d4 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_columns_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_columns_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, List, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_database_columns_operations import build_get_request, build_list_by_database_request, build_list_by_table_request -T = TypeVar('T') +from ...operations._managed_database_columns_operations import ( + build_get_request, + build_list_by_database_request, + build_list_by_table_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedDatabaseColumnsOperations: """ .. warning:: @@ -43,7 +55,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( self, @@ -56,62 +67,56 @@ def list_by_database( order_by: Optional[List[str]] = None, skiptoken: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable[_models.DatabaseColumnListResult]: + ) -> AsyncIterable["_models.DatabaseColumn"]: """List managed database columns. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema: Default value is None. + :param schema: Default value is None. :type schema: list[str] - :param table: Default value is None. + :param table: Default value is None. :type table: list[str] - :param column: Default value is None. + :param column: Default value is None. :type column: list[str] - :param order_by: Default value is None. + :param order_by: Default value is None. :type order_by: list[str] :param skiptoken: An opaque token that identifies a starting point in the collection. Default value is None. :type skiptoken: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseColumnListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseColumnListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseColumn or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseColumn] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseColumnListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseColumnListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, schema=schema, table=table, column=column, order_by=order_by, skiptoken=skiptoken, - template_url=self.list_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -119,22 +124,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - schema=schema, - table=table, - column=column, - order_by=order_by, - skiptoken=skiptoken, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -150,10 +140,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -163,11 +151,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/columns"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/columns"} # type: ignore @distributed_trace def list_by_table( @@ -179,46 +165,40 @@ def list_by_table( table_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable[_models.DatabaseColumnListResult]: + ) -> AsyncIterable["_models.DatabaseColumn"]: """List managed database columns. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseColumnListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseColumnListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseColumn or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseColumn] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseColumnListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseColumnListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_table_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -226,9 +206,9 @@ def prepare_request(next_link=None): schema_name=schema_name, table_name=table_name, subscription_id=self._config.subscription_id, - api_version=api_version, filter=filter, - template_url=self.list_by_table.metadata['url'], + api_version=api_version, + template_url=self.list_by_table.metadata["url"], headers=_headers, params=_params, ) @@ -236,20 +216,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_table_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - schema_name=schema_name, - table_name=table_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -265,10 +232,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -278,11 +243,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_table.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns"} # type: ignore + list_by_table.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns"} # type: ignore @distributed_trace_async async def get( @@ -298,38 +261,32 @@ async def get( """Get managed database column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseColumn, or the result of cls(response) + :return: DatabaseColumn or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseColumn - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseColumn] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseColumn] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -339,7 +296,7 @@ async def get( column_name=column_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -347,22 +304,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseColumn', pipeline_response) + deserialized = self._deserialize("DatabaseColumn", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_queries_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_queries_operations.py index 7595f7fd6723a..c6e44f0144f7f 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_queries_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_queries_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._managed_database_queries_operations import build_get_request, build_list_by_query_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedDatabaseQueriesOperations: """ .. warning:: @@ -43,47 +51,35 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - query_id: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, database_name: str, query_id: str, **kwargs: Any ) -> _models.ManagedInstanceQuery: """Get query by query id. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param query_id: + :param query_id: Required. :type query_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceQuery, or the result of cls(response) + :return: ManagedInstanceQuery or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceQuery - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceQuery] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceQuery] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -91,7 +87,7 @@ async def get( query_id=query_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -99,25 +95,23 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceQuery', pipeline_response) + deserialized = self._deserialize("ManagedInstanceQuery", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/queries/{queryId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/queries/{queryId}"} # type: ignore @distributed_trace def list_by_query( @@ -130,59 +124,53 @@ def list_by_query( end_time: Optional[str] = None, interval: Optional[Union[str, "_models.QueryTimeGrainType"]] = None, **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstanceQueryStatistics]: + ) -> AsyncIterable["_models.QueryStatistics"]: """Get query execution statistics by query id. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param query_id: + :param query_id: Required. :type query_id: str :param start_time: Start time for observed period. Default value is None. :type start_time: str :param end_time: End time for observed period. Default value is None. :type end_time: str - :param interval: The time step to be used to summarize the metric values. Default value is - None. + :param interval: The time step to be used to summarize the metric values. Known values are: + "PT1H" and "P1D". Default value is None. :type interval: str or ~azure.mgmt.sql.models.QueryTimeGrainType - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceQueryStatistics or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceQueryStatistics] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either QueryStatistics or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.QueryStatistics] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceQueryStatistics] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceQueryStatistics] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_query_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, query_id=query_id, subscription_id=self._config.subscription_id, - api_version=api_version, start_time=start_time, end_time=end_time, interval=interval, - template_url=self.list_by_query.metadata['url'], + api_version=api_version, + template_url=self.list_by_query.metadata["url"], headers=_headers, params=_params, ) @@ -190,21 +178,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_query_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - query_id=query_id, - subscription_id=self._config.subscription_id, - api_version=api_version, - start_time=start_time, - end_time=end_time, - interval=interval, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -220,10 +194,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -233,8 +205,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_query.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/queries/{queryId}/statistics"} # type: ignore + list_by_query.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/queries/{queryId}/statistics"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_recommended_sensitivity_labels_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_recommended_sensitivity_labels_operations.py index 881a326114d4e..adef9d8a75411 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_recommended_sensitivity_labels_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_recommended_sensitivity_labels_operations.py @@ -6,9 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -19,9 +25,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._managed_database_recommended_sensitivity_labels_operations import build_update_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedDatabaseRecommendedSensitivityLabelsOperations: """ .. warning:: @@ -41,48 +49,113 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace_async + @overload async def update( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, managed_instance_name: str, database_name: str, parameters: _models.RecommendedSensitivityLabelUpdateList, + *, + content_type: str = "application/json", **kwargs: Any ) -> None: """Update recommended sensitivity labels states of a given database using an operations batch. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.RecommendedSensitivityLabelUpdateList - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> None: + """Update recommended sensitivity labels states of a given database using an operations batch. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Required. + :type parameters: IO + :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: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace_async + async def update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.RecommendedSensitivityLabelUpdateList, IO], + **kwargs: Any + ) -> None: + """Update recommended sensitivity labels states of a given database using an operations batch. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.RecommendedSensitivityLabelUpdateList 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 + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'RecommendedSensitivityLabelUpdateList') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "RecommendedSensitivityLabelUpdateList") request = build_update_request( resource_group_name=resource_group_name, @@ -92,7 +165,8 @@ async def update( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -100,10 +174,9 @@ async def update( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -113,5 +186,4 @@ async def update( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/recommendedSensitivityLabels"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/recommendedSensitivityLabels"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_restore_details_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_restore_details_operations.py index e5dcb841dcd5d..db0e6efbafc74 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_restore_details_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_restore_details_operations.py @@ -8,7 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Optional, TypeVar, Union -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -19,9 +25,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._managed_database_restore_details_operations import build_get_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedDatabaseRestoreDetailsOperations: """ .. warning:: @@ -41,7 +49,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -54,34 +61,28 @@ async def get( """Gets managed database restore details. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param restore_details_name: The name of the restore details to retrieve. + :param restore_details_name: The name of the restore details to retrieve. "Default" Required. :type restore_details_name: str or ~azure.mgmt.sql.models.RestoreDetailsName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedDatabaseRestoreDetailsResult, or the result of cls(response) + :return: ManagedDatabaseRestoreDetailsResult or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedDatabaseRestoreDetailsResult - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabaseRestoreDetailsResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseRestoreDetailsResult] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -89,7 +90,7 @@ async def get( restore_details_name=restore_details_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,22 +98,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedDatabaseRestoreDetailsResult', pipeline_response) + deserialized = self._deserialize("ManagedDatabaseRestoreDetailsResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/restoreDetails/{restoreDetailsName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/restoreDetails/{restoreDetailsName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_schemas_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_schemas_operations.py index cc78151f0aad8..f322b86ecf123 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_schemas_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_schemas_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._managed_database_schemas_operations import build_get_request, build_list_by_database_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedDatabaseSchemasOperations: """ .. warning:: @@ -43,7 +51,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( self, @@ -52,50 +59,44 @@ def list_by_database( database_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable[_models.DatabaseSchemaListResult]: + ) -> AsyncIterable["_models.DatabaseSchema"]: """List managed database schemas. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseSchemaListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseSchemaListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseSchema or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseSchema] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseSchemaListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseSchemaListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, filter=filter, - template_url=self.list_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -103,18 +104,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -130,10 +120,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -143,52 +131,39 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - schema_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, database_name: str, schema_name: str, **kwargs: Any ) -> _models.DatabaseSchema: """Get managed database schema. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseSchema, or the result of cls(response) + :return: DatabaseSchema or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseSchema - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseSchema] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseSchema] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -196,7 +171,7 @@ async def get( schema_name=schema_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -204,22 +179,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseSchema', pipeline_response) + deserialized = self._deserialize("DatabaseSchema", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_security_alert_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_security_alert_policies_operations.py index 3403bc35185a8..d5a79a0c01ab0 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_security_alert_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_security_alert_policies_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_database_security_alert_policies_operations import build_create_or_update_request, build_get_request, build_list_by_database_request -T = TypeVar('T') +from ...operations._managed_database_security_alert_policies_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedDatabaseSecurityAlertPoliciesOperations: """ .. warning:: @@ -43,7 +55,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -56,35 +67,29 @@ async def get( """Gets a managed database's security alert policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the managed database for which the security alert policy is - defined. + defined. Required. :type database_name: str - :param security_alert_policy_name: The name of the security alert policy. + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedDatabaseSecurityAlertPolicy, or the result of cls(response) + :return: ManagedDatabaseSecurityAlertPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedDatabaseSecurityAlertPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabaseSecurityAlertPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseSecurityAlertPolicy] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -92,7 +97,7 @@ async def get( security_alert_policy_name=security_alert_policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -100,27 +105,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedDatabaseSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ManagedDatabaseSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, @@ -128,43 +131,118 @@ async def create_or_update( database_name: str, security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], parameters: _models.ManagedDatabaseSecurityAlertPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.ManagedDatabaseSecurityAlertPolicy: """Creates or updates a database's security alert policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the managed database for which the security alert policy is - defined. + defined. Required. :type database_name: str - :param security_alert_policy_name: The name of the security alert policy. + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName - :param parameters: The database security alert policy. + :param parameters: The database security alert policy. Required. :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseSecurityAlertPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: ManagedDatabaseSecurityAlertPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedDatabaseSecurityAlertPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.ManagedDatabaseSecurityAlertPolicy: + """Creates or updates a database's security alert policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the managed database for which the security alert policy is + defined. Required. + :type database_name: str + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. + :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName + :param parameters: The database security alert policy. Required. + :type parameters: IO + :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: ManagedDatabaseSecurityAlertPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedDatabaseSecurityAlertPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], + parameters: Union[_models.ManagedDatabaseSecurityAlertPolicy, IO], + **kwargs: Any + ) -> _models.ManagedDatabaseSecurityAlertPolicy: + """Creates or updates a database's security alert policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the managed database for which the security alert policy is + defined. Required. + :type database_name: str + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. + :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName + :param parameters: The database security alert policy. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseSecurityAlertPolicy 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 - :return: ManagedDatabaseSecurityAlertPolicy, or the result of cls(response) + :return: ManagedDatabaseSecurityAlertPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedDatabaseSecurityAlertPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabaseSecurityAlertPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseSecurityAlertPolicy] - _json = self._serialize.body(parameters, 'ManagedDatabaseSecurityAlertPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedDatabaseSecurityAlertPolicy") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -175,7 +253,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -183,10 +262,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -194,67 +272,58 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('ManagedDatabaseSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ManagedDatabaseSecurityAlertPolicy", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedDatabaseSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ManagedDatabaseSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedDatabaseSecurityAlertPolicyListResult]: + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedDatabaseSecurityAlertPolicy"]: """Gets a list of managed database's security alert policies. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the managed database for which the security alert policies - are defined. + are defined. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedDatabaseSecurityAlertPolicyListResult or - the result of cls(response) + :return: An iterator like instance of either ManagedDatabaseSecurityAlertPolicy or the result + of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedDatabaseSecurityAlertPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedDatabaseSecurityAlertPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabaseSecurityAlertPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseSecurityAlertPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -262,17 +331,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -288,10 +347,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -301,8 +358,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_security_events_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_security_events_operations.py index fe3dc6de3eefa..f10bbd722d80d 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_security_events_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_security_events_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,9 +26,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._managed_database_security_events_operations import build_list_by_database_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedDatabaseSecurityEventsOperations: """ .. warning:: @@ -42,7 +50,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( self, @@ -54,16 +61,16 @@ def list_by_database( top: Optional[int] = None, skiptoken: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable[_models.SecurityEventCollection]: + ) -> AsyncIterable["_models.SecurityEvent"]: """Gets a list of security events. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the managed database for which the security events are - retrieved. + retrieved. Required. :type database_name: str :param filter: An OData filter expression that filters elements in the collection. Default value is None. @@ -75,39 +82,34 @@ def list_by_database( :param skiptoken: An opaque token that identifies a starting point in the collection. Default value is None. :type skiptoken: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SecurityEventCollection or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SecurityEventCollection] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SecurityEvent or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SecurityEvent] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SecurityEventCollection] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SecurityEventCollection] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, filter=filter, skip=skip, top=top, skiptoken=skiptoken, - template_url=self.list_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -115,21 +117,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - filter=filter, - skip=skip, - top=top, - skiptoken=skiptoken, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -145,10 +133,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -158,8 +144,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityEvents"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityEvents"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_sensitivity_labels_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_sensitivity_labels_operations.py index 0dee6ead85e06..e667f42e5856a 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_sensitivity_labels_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_sensitivity_labels_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,21 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_database_sensitivity_labels_operations import build_create_or_update_request, build_delete_request, build_disable_recommendation_request, build_enable_recommendation_request, build_get_request, build_list_current_by_database_request, build_list_recommended_by_database_request, build_update_request -T = TypeVar('T') +from ...operations._managed_database_sensitivity_labels_operations import ( + build_create_or_update_request, + build_delete_request, + build_disable_recommendation_request, + build_enable_recommendation_request, + build_get_request, + build_list_current_by_database_request, + build_list_recommended_by_database_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedDatabaseSensitivityLabelsOperations: """ .. warning:: @@ -43,7 +60,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -59,40 +75,35 @@ async def get( """Gets the sensitivity label of a given column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :param sensitivity_label_source: The source of the sensitivity label. + :param sensitivity_label_source: The source of the sensitivity label. Known values are: + "current" and "recommended". Required. :type sensitivity_label_source: str or ~azure.mgmt.sql.models.SensitivityLabelSource - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SensitivityLabel, or the result of cls(response) + :return: SensitivityLabel or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SensitivityLabel - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SensitivityLabel] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SensitivityLabel] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -103,7 +114,7 @@ async def get( sensitivity_label_source=sensitivity_label_source, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -111,27 +122,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SensitivityLabel', pipeline_response) + deserialized = self._deserialize("SensitivityLabel", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore - - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, @@ -141,50 +150,141 @@ async def create_or_update( table_name: str, column_name: str, parameters: _models.SensitivityLabel, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.SensitivityLabel: """Creates or updates the sensitivity label of a given column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :param parameters: The column sensitivity label resource. + :param parameters: The column sensitivity label resource. Required. :type parameters: ~azure.mgmt.sql.models.SensitivityLabel + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str :keyword sensitivity_label_source: The source of the sensitivity label. Default value is "current". Note that overriding this default value may result in unsupported behavior. :paramtype sensitivity_label_source: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SensitivityLabel, or the result of cls(response) + :return: SensitivityLabel or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SensitivityLabel - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + schema_name: str, + table_name: str, + column_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.SensitivityLabel: + """Creates or updates the sensitivity label of a given column. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param schema_name: The name of the schema. Required. + :type schema_name: str + :param table_name: The name of the table. Required. + :type table_name: str + :param column_name: The name of the column. Required. + :type column_name: str + :param parameters: The column sensitivity label resource. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword sensitivity_label_source: The source of the sensitivity label. Default value is + "current". Note that overriding this default value may result in unsupported behavior. + :paramtype sensitivity_label_source: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SensitivityLabel or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.SensitivityLabel + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + schema_name: str, + table_name: str, + column_name: str, + parameters: Union[_models.SensitivityLabel, IO], + **kwargs: Any + ) -> _models.SensitivityLabel: + """Creates or updates the sensitivity label of a given column. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param schema_name: The name of the schema. Required. + :type schema_name: str + :param table_name: The name of the table. Required. + :type table_name: str + :param column_name: The name of the column. Required. + :type column_name: str + :param parameters: The column sensitivity label resource. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.SensitivityLabel or IO + :keyword sensitivity_label_source: The source of the sensitivity label. Default value is + "current". Note that overriding this default value may result in unsupported behavior. + :paramtype sensitivity_label_source: str + :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 + :return: SensitivityLabel or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.SensitivityLabel + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "current") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.SensitivityLabel] + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "current") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.SensitivityLabel] - _json = self._serialize.body(parameters, 'SensitivityLabel') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SensitivityLabel") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -198,7 +298,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -206,10 +307,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -217,18 +317,17 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('SensitivityLabel', pipeline_response) + deserialized = self._deserialize("SensitivityLabel", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('SensitivityLabel', pipeline_response) + deserialized = self._deserialize("SensitivityLabel", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -244,42 +343,36 @@ async def delete( # pylint: disable=inconsistent-return-statements """Deletes the sensitivity label of a given column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str :keyword sensitivity_label_source: The source of the sensitivity label. Default value is "current". Note that overriding this default value may result in unsupported behavior. :paramtype sensitivity_label_source: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "current") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "current") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -290,7 +383,7 @@ async def delete( # pylint: disable=inconsistent-return-statements subscription_id=self._config.subscription_id, sensitivity_label_source=sensitivity_label_source, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -298,10 +391,9 @@ async def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -311,8 +403,7 @@ async def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore @distributed_trace_async async def disable_recommendation( # pylint: disable=inconsistent-return-statements @@ -328,42 +419,36 @@ async def disable_recommendation( # pylint: disable=inconsistent-return-stateme """Disables sensitivity recommendations on a given column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :keyword sensitivity_label_source: Default value is "recommended". Note that overriding this + :keyword sensitivity_label_source: Default value is "recommended". Note that overriding this default value may result in unsupported behavior. :paramtype sensitivity_label_source: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "recommended") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "recommended") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_disable_recommendation_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -374,7 +459,7 @@ async def disable_recommendation( # pylint: disable=inconsistent-return-stateme subscription_id=self._config.subscription_id, sensitivity_label_source=sensitivity_label_source, api_version=api_version, - template_url=self.disable_recommendation.metadata['url'], + template_url=self.disable_recommendation.metadata["url"], headers=_headers, params=_params, ) @@ -382,10 +467,9 @@ async def disable_recommendation( # pylint: disable=inconsistent-return-stateme request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -395,8 +479,7 @@ async def disable_recommendation( # pylint: disable=inconsistent-return-stateme if cls: return cls(pipeline_response, None, {}) - disable_recommendation.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/disable"} # type: ignore - + disable_recommendation.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/disable"} # type: ignore @distributed_trace_async async def enable_recommendation( # pylint: disable=inconsistent-return-statements @@ -413,42 +496,36 @@ async def enable_recommendation( # pylint: disable=inconsistent-return-statemen on all columns). :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :keyword sensitivity_label_source: Default value is "recommended". Note that overriding this + :keyword sensitivity_label_source: Default value is "recommended". Note that overriding this default value may result in unsupported behavior. :paramtype sensitivity_label_source: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "recommended") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "recommended") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_enable_recommendation_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -459,7 +536,7 @@ async def enable_recommendation( # pylint: disable=inconsistent-return-statemen subscription_id=self._config.subscription_id, sensitivity_label_source=sensitivity_label_source, api_version=api_version, - template_url=self.enable_recommendation.metadata['url'], + template_url=self.enable_recommendation.metadata["url"], headers=_headers, params=_params, ) @@ -467,10 +544,9 @@ async def enable_recommendation( # pylint: disable=inconsistent-return-statemen request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -480,8 +556,7 @@ async def enable_recommendation( # pylint: disable=inconsistent-return-statemen if cls: return cls(pipeline_response, None, {}) - enable_recommendation.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/enable"} # type: ignore - + enable_recommendation.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/enable"} # type: ignore @distributed_trace def list_current_by_database( @@ -493,56 +568,50 @@ def list_current_by_database( count: Optional[bool] = None, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable[_models.SensitivityLabelListResult]: + ) -> AsyncIterable["_models.SensitivityLabel"]: """Gets the sensitivity labels of a given database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param skip_token: Default value is None. + :param skip_token: Default value is None. :type skip_token: str - :param count: Default value is None. + :param count: Default value is None. :type count: bool :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SensitivityLabelListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SensitivityLabelListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SensitivityLabel or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SensitivityLabel] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SensitivityLabelListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SensitivityLabelListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_current_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, skip_token=skip_token, count=count, filter=filter, - template_url=self.list_current_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_current_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -550,20 +619,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_current_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - skip_token=skip_token, - count=count, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -579,10 +635,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -592,53 +646,117 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_current_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/currentSensitivityLabels"} # type: ignore + list_current_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/currentSensitivityLabels"} # type: ignore - @distributed_trace_async + @overload async def update( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, managed_instance_name: str, database_name: str, parameters: _models.SensitivityLabelUpdateList, + *, + content_type: str = "application/json", **kwargs: Any ) -> None: """Update sensitivity labels of a given database using an operations batch. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.SensitivityLabelUpdateList - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> None: + """Update sensitivity labels of a given database using an operations batch. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Required. + :type parameters: IO + :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: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.SensitivityLabelUpdateList, IO], + **kwargs: Any + ) -> None: + """Update sensitivity labels of a given database using an operations batch. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.SensitivityLabelUpdateList 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 + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'SensitivityLabelUpdateList') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SensitivityLabelUpdateList") request = build_update_request( resource_group_name=resource_group_name, @@ -648,7 +766,8 @@ async def update( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -656,10 +775,9 @@ async def update( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -669,8 +787,7 @@ async def update( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/currentSensitivityLabels"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/currentSensitivityLabels"} # type: ignore @distributed_trace def list_recommended_by_database( @@ -682,17 +799,17 @@ def list_recommended_by_database( include_disabled_recommendations: Optional[bool] = None, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable[_models.SensitivityLabelListResult]: + ) -> AsyncIterable["_models.SensitivityLabel"]: """Gets the sensitivity labels of a given database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param skip_token: Default value is None. + :param skip_token: Default value is None. :type skip_token: str :param include_disabled_recommendations: Specifies whether to include disabled recommendations or not. Default value is None. @@ -700,39 +817,33 @@ def list_recommended_by_database( :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SensitivityLabelListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SensitivityLabelListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SensitivityLabel or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SensitivityLabel] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SensitivityLabelListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SensitivityLabelListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_recommended_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, skip_token=skip_token, include_disabled_recommendations=include_disabled_recommendations, filter=filter, - template_url=self.list_recommended_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_recommended_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -740,20 +851,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_recommended_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - skip_token=skip_token, - include_disabled_recommendations=include_disabled_recommendations, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -769,10 +867,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -782,8 +878,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_recommended_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/recommendedSensitivityLabels"} # type: ignore + list_recommended_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/recommendedSensitivityLabels"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_tables_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_tables_operations.py index 4c84261ee4216..46087ca0fd4fe 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_tables_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_tables_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._managed_database_tables_operations import build_get_request, build_list_by_schema_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedDatabaseTablesOperations: """ .. warning:: @@ -43,7 +51,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_schema( self, @@ -53,52 +60,47 @@ def list_by_schema( schema_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable[_models.DatabaseTableListResult]: + ) -> AsyncIterable["_models.DatabaseTable"]: """List managed database tables. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseTableListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseTableListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseTable or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseTable] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseTableListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseTableListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_schema_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, schema_name=schema_name, subscription_id=self._config.subscription_id, - api_version=api_version, filter=filter, - template_url=self.list_by_schema.metadata['url'], + api_version=api_version, + template_url=self.list_by_schema.metadata["url"], headers=_headers, params=_params, ) @@ -106,19 +108,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_schema_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - schema_name=schema_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -134,10 +124,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -147,11 +135,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_schema.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables"} # type: ignore + list_by_schema.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables"} # type: ignore @distributed_trace_async async def get( @@ -166,36 +152,30 @@ async def get( """Get managed database table. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseTable, or the result of cls(response) + :return: DatabaseTable or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseTable - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseTable] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseTable] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -204,7 +184,7 @@ async def get( table_name=table_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -212,22 +192,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseTable', pipeline_response) + deserialized = self._deserialize("DatabaseTable", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_transparent_data_encryption_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_transparent_data_encryption_operations.py index e39dff17918c8..79c691de00534 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_transparent_data_encryption_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_transparent_data_encryption_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_database_transparent_data_encryption_operations import build_create_or_update_request, build_get_request, build_list_by_database_request -T = TypeVar('T') +from ...operations._managed_database_transparent_data_encryption_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedDatabaseTransparentDataEncryptionOperations: """ .. warning:: @@ -43,7 +55,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -56,35 +67,29 @@ async def get( """Gets a managed database's transparent data encryption. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the managed database for which the transparent data - encryption is defined. + encryption is defined. Required. :type database_name: str - :param tde_name: The name of the transparent data encryption configuration. + :param tde_name: The name of the transparent data encryption configuration. "current" Required. :type tde_name: str or ~azure.mgmt.sql.models.TransparentDataEncryptionName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedTransparentDataEncryption, or the result of cls(response) + :return: ManagedTransparentDataEncryption or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedTransparentDataEncryption - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedTransparentDataEncryption] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedTransparentDataEncryption] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -92,7 +97,7 @@ async def get( tde_name=tde_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -100,27 +105,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedTransparentDataEncryption', pipeline_response) + deserialized = self._deserialize("ManagedTransparentDataEncryption", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption/{tdeName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption/{tdeName}"} # type: ignore - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, @@ -128,43 +131,118 @@ async def create_or_update( database_name: str, tde_name: Union[str, "_models.TransparentDataEncryptionName"], parameters: _models.ManagedTransparentDataEncryption, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.ManagedTransparentDataEncryption: """Updates a database's transparent data encryption configuration. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the managed database for which the security alert policy is - defined. + defined. Required. :type database_name: str - :param tde_name: The name of the transparent data encryption configuration. + :param tde_name: The name of the transparent data encryption configuration. "current" Required. :type tde_name: str or ~azure.mgmt.sql.models.TransparentDataEncryptionName - :param parameters: The database transparent data encryption. + :param parameters: The database transparent data encryption. Required. :type parameters: ~azure.mgmt.sql.models.ManagedTransparentDataEncryption - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: ManagedTransparentDataEncryption or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedTransparentDataEncryption + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + tde_name: Union[str, "_models.TransparentDataEncryptionName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.ManagedTransparentDataEncryption: + """Updates a database's transparent data encryption configuration. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the managed database for which the security alert policy is + defined. Required. + :type database_name: str + :param tde_name: The name of the transparent data encryption configuration. "current" Required. + :type tde_name: str or ~azure.mgmt.sql.models.TransparentDataEncryptionName + :param parameters: The database transparent data encryption. Required. + :type parameters: IO + :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: ManagedTransparentDataEncryption or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedTransparentDataEncryption + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + tde_name: Union[str, "_models.TransparentDataEncryptionName"], + parameters: Union[_models.ManagedTransparentDataEncryption, IO], + **kwargs: Any + ) -> _models.ManagedTransparentDataEncryption: + """Updates a database's transparent data encryption configuration. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the managed database for which the security alert policy is + defined. Required. + :type database_name: str + :param tde_name: The name of the transparent data encryption configuration. "current" Required. + :type tde_name: str or ~azure.mgmt.sql.models.TransparentDataEncryptionName + :param parameters: The database transparent data encryption. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedTransparentDataEncryption 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 - :return: ManagedTransparentDataEncryption, or the result of cls(response) + :return: ManagedTransparentDataEncryption or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedTransparentDataEncryption - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedTransparentDataEncryption] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedTransparentDataEncryption] - _json = self._serialize.body(parameters, 'ManagedTransparentDataEncryption') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedTransparentDataEncryption") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -175,7 +253,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -183,10 +262,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -194,67 +272,58 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('ManagedTransparentDataEncryption', pipeline_response) + deserialized = self._deserialize("ManagedTransparentDataEncryption", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedTransparentDataEncryption', pipeline_response) + deserialized = self._deserialize("ManagedTransparentDataEncryption", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption/{tdeName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption/{tdeName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedTransparentDataEncryptionListResult]: + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedTransparentDataEncryption"]: """Gets a list of managed database's transparent data encryptions. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the managed database for which the transparent data - encryption is defined. + encryption is defined. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedTransparentDataEncryptionListResult or the - result of cls(response) + :return: An iterator like instance of either ManagedTransparentDataEncryption or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedTransparentDataEncryptionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedTransparentDataEncryption] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedTransparentDataEncryptionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedTransparentDataEncryptionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -262,17 +331,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -288,10 +347,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -301,8 +358,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_vulnerability_assessment_rule_baselines_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_vulnerability_assessment_rule_baselines_operations.py index 9ff775a10d7a2..c21f20884ae87 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_vulnerability_assessment_rule_baselines_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_vulnerability_assessment_rule_baselines_operations.py @@ -6,9 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar, Union - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -18,10 +24,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_database_vulnerability_assessment_rule_baselines_operations import build_create_or_update_request, build_delete_request, build_get_request -T = TypeVar('T') +from ...operations._managed_database_vulnerability_assessment_rule_baselines_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations: """ .. warning:: @@ -41,7 +53,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -56,40 +67,36 @@ async def get( """Gets a database's vulnerability assessment rule baseline. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the database for which the vulnerability assessment rule - baseline is defined. + baseline is defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param rule_id: The vulnerability assessment rule ID. + :param rule_id: The vulnerability assessment rule ID. Required. :type rule_id: str :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a - baseline on a database level rule and master for server level rule). + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseVulnerabilityAssessmentRuleBaseline, or the result of cls(response) + :return: DatabaseVulnerabilityAssessmentRuleBaseline or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentRuleBaseline] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentRuleBaseline] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -99,7 +106,7 @@ async def get( baseline_name=baseline_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -107,27 +114,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseVulnerabilityAssessmentRuleBaseline', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessmentRuleBaseline", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, @@ -137,48 +142,143 @@ async def create_or_update( rule_id: str, baseline_name: Union[str, "_models.VulnerabilityAssessmentPolicyBaselineName"], parameters: _models.DatabaseVulnerabilityAssessmentRuleBaseline, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DatabaseVulnerabilityAssessmentRuleBaseline: """Creates or updates a database's vulnerability assessment rule baseline. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the database for which the vulnerability assessment rule - baseline is defined. + baseline is defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param rule_id: The vulnerability assessment rule ID. + :param rule_id: The vulnerability assessment rule ID. Required. :type rule_id: str :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a - baseline on a database level rule and master for server level rule). + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName - :param parameters: The requested rule baseline resource. + :param parameters: The requested rule baseline resource. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: DatabaseVulnerabilityAssessmentRuleBaseline or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + rule_id: str, + baseline_name: Union[str, "_models.VulnerabilityAssessmentPolicyBaselineName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DatabaseVulnerabilityAssessmentRuleBaseline: + """Creates or updates a database's vulnerability assessment rule baseline. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database for which the vulnerability assessment rule + baseline is defined. Required. + :type database_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param rule_id: The vulnerability assessment rule ID. Required. + :type rule_id: str + :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. + :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName + :param parameters: The requested rule baseline resource. Required. + :type parameters: IO + :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: DatabaseVulnerabilityAssessmentRuleBaseline, or the result of cls(response) + :return: DatabaseVulnerabilityAssessmentRuleBaseline or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + rule_id: str, + baseline_name: Union[str, "_models.VulnerabilityAssessmentPolicyBaselineName"], + parameters: Union[_models.DatabaseVulnerabilityAssessmentRuleBaseline, IO], + **kwargs: Any + ) -> _models.DatabaseVulnerabilityAssessmentRuleBaseline: + """Creates or updates a database's vulnerability assessment rule baseline. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database for which the vulnerability assessment rule + baseline is defined. Required. + :type database_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param rule_id: The vulnerability assessment rule ID. Required. + :type rule_id: str + :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. + :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName + :param parameters: The requested rule baseline resource. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline 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 + :return: DatabaseVulnerabilityAssessmentRuleBaseline or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentRuleBaseline] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentRuleBaseline] - _json = self._serialize.body(parameters, 'DatabaseVulnerabilityAssessmentRuleBaseline') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseVulnerabilityAssessmentRuleBaseline") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -191,7 +291,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -199,25 +300,23 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseVulnerabilityAssessmentRuleBaseline', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessmentRuleBaseline", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -233,40 +332,36 @@ async def delete( # pylint: disable=inconsistent-return-statements """Removes the database's vulnerability assessment rule baseline. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the database for which the vulnerability assessment rule - baseline is defined. + baseline is defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param rule_id: The vulnerability assessment rule ID. + :param rule_id: The vulnerability assessment rule ID. Required. :type rule_id: str :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a - baseline on a database level rule and master for server level rule). + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -276,7 +371,7 @@ async def delete( # pylint: disable=inconsistent-return-statements baseline_name=baseline_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -284,10 +379,9 @@ async def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -297,5 +391,4 @@ async def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_vulnerability_assessment_scans_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_vulnerability_assessment_scans_operations.py index 2477b8b355981..b4cef353f8938 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_vulnerability_assessment_scans_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_vulnerability_assessment_scans_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_database_vulnerability_assessment_scans_operations import build_export_request, build_get_request, build_initiate_scan_request_initial, build_list_by_database_request -T = TypeVar('T') +from ...operations._managed_database_vulnerability_assessment_scans_operations import ( + build_export_request, + build_get_request, + build_initiate_scan_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedDatabaseVulnerabilityAssessmentScansOperations: """ .. warning:: @@ -45,7 +58,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - async def _initiate_scan_initial( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, @@ -55,19 +67,16 @@ async def _initiate_scan_initial( # pylint: disable=inconsistent-return-stateme scan_id: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_initiate_scan_request_initial( + request = build_initiate_scan_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, @@ -75,7 +84,7 @@ async def _initiate_scan_initial( # pylint: disable=inconsistent-return-stateme scan_id=scan_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._initiate_scan_initial.metadata['url'], + template_url=self._initiate_scan_initial.metadata["url"], headers=_headers, params=_params, ) @@ -83,10 +92,9 @@ async def _initiate_scan_initial( # pylint: disable=inconsistent-return-stateme request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -96,11 +104,10 @@ async def _initiate_scan_initial( # pylint: disable=inconsistent-return-stateme if cls: return cls(pipeline_response, None, {}) - _initiate_scan_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan"} # type: ignore - + _initiate_scan_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan"} # type: ignore @distributed_trace_async - async def begin_initiate_scan( # pylint: disable=inconsistent-return-statements + async def begin_initiate_scan( self, resource_group_name: str, managed_instance_name: str, @@ -112,19 +119,17 @@ async def begin_initiate_scan( # pylint: disable=inconsistent-return-statements """Executes a Vulnerability Assessment database scan. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param scan_id: The vulnerability assessment scan Id of the scan to retrieve. + :param scan_id: The vulnerability assessment scan Id of the scan to retrieve. Required. :type scan_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -135,19 +140,16 @@ async def begin_initiate_scan( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._initiate_scan_initial( # type: ignore resource_group_name=resource_group_name, @@ -156,37 +158,33 @@ async def begin_initiate_scan( # pylint: disable=inconsistent-return-statements vulnerability_assessment_name=vulnerability_assessment_name, scan_id=scan_id, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_initiate_scan.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan"} # type: ignore + begin_initiate_scan.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan"} # type: ignore @distributed_trace_async async def export( @@ -201,36 +199,31 @@ async def export( """Convert an existing scan result to a human readable format. If already exists nothing happens. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the scanned database. + :param database_name: The name of the scanned database. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param scan_id: The vulnerability assessment scan Id. + :param scan_id: The vulnerability assessment scan Id. Required. :type scan_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseVulnerabilityAssessmentScansExport, or the result of cls(response) + :return: DatabaseVulnerabilityAssessmentScansExport or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentScansExport - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentScansExport] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentScansExport] - request = build_export_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -239,7 +232,7 @@ async def export( scan_id=scan_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.export.metadata['url'], + template_url=self.export.metadata["url"], headers=_headers, params=_params, ) @@ -247,10 +240,9 @@ async def export( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -258,18 +250,17 @@ async def export( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('DatabaseVulnerabilityAssessmentScansExport', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessmentScansExport", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DatabaseVulnerabilityAssessmentScansExport', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessmentScansExport", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - export.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/export"} # type: ignore - + export.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/export"} # type: ignore @distributed_trace def list_by_database( @@ -279,41 +270,38 @@ def list_by_database( database_name: str, vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], **kwargs: Any - ) -> AsyncIterable[_models.VulnerabilityAssessmentScanRecordListResult]: + ) -> AsyncIterable["_models.VulnerabilityAssessmentScanRecord"]: """Lists the vulnerability assessment scans of a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VulnerabilityAssessmentScanRecordListResult or the - result of cls(response) + :return: An iterator like instance of either VulnerabilityAssessmentScanRecord or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.VulnerabilityAssessmentScanRecordListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.VulnerabilityAssessmentScanRecord] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VulnerabilityAssessmentScanRecordListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VulnerabilityAssessmentScanRecordListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -321,7 +309,7 @@ def prepare_request(next_link=None): vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -329,18 +317,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - vulnerability_assessment_name=vulnerability_assessment_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -356,10 +333,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -369,11 +344,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans"} # type: ignore @distributed_trace_async async def get( @@ -388,36 +361,31 @@ async def get( """Gets a vulnerability assessment scan record of a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param scan_id: The vulnerability assessment scan Id of the scan to retrieve. + :param scan_id: The vulnerability assessment scan Id of the scan to retrieve. Required. :type scan_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VulnerabilityAssessmentScanRecord, or the result of cls(response) + :return: VulnerabilityAssessmentScanRecord or the result of cls(response) :rtype: ~azure.mgmt.sql.models.VulnerabilityAssessmentScanRecord - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VulnerabilityAssessmentScanRecord] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VulnerabilityAssessmentScanRecord] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -426,7 +394,7 @@ async def get( scan_id=scan_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -434,22 +402,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('VulnerabilityAssessmentScanRecord', pipeline_response) + deserialized = self._deserialize("VulnerabilityAssessmentScanRecord", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_vulnerability_assessments_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_vulnerability_assessments_operations.py index 5cd551b415e6d..4186d859fb887 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_vulnerability_assessments_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_database_vulnerability_assessments_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_database_vulnerability_assessments_operations import build_create_or_update_request, build_delete_request, build_get_request, build_list_by_database_request -T = TypeVar('T') +from ...operations._managed_database_vulnerability_assessments_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedDatabaseVulnerabilityAssessmentsOperations: """ .. warning:: @@ -43,7 +56,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -56,35 +68,30 @@ async def get( """Gets the database's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the database for which the vulnerability assessment is - defined. + defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseVulnerabilityAssessment, or the result of cls(response) + :return: DatabaseVulnerabilityAssessment or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessment] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessment] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -92,7 +99,7 @@ async def get( vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -100,27 +107,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, @@ -128,43 +133,120 @@ async def create_or_update( database_name: str, vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], parameters: _models.DatabaseVulnerabilityAssessment, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DatabaseVulnerabilityAssessment: """Creates or updates the database's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the database for which the vulnerability assessment is - defined. + defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param parameters: The requested resource. + :param parameters: The requested resource. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: DatabaseVulnerabilityAssessment or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DatabaseVulnerabilityAssessment: + """Creates or updates the database's vulnerability assessment. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database for which the vulnerability assessment is + defined. Required. + :type database_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param parameters: The requested resource. Required. + :type parameters: IO + :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: DatabaseVulnerabilityAssessment, or the result of cls(response) + :return: DatabaseVulnerabilityAssessment or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + parameters: Union[_models.DatabaseVulnerabilityAssessment, IO], + **kwargs: Any + ) -> _models.DatabaseVulnerabilityAssessment: + """Creates or updates the database's vulnerability assessment. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database for which the vulnerability assessment is + defined. Required. + :type database_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param parameters: The requested resource. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment 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 + :return: DatabaseVulnerabilityAssessment or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessment] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessment] - _json = self._serialize.body(parameters, 'DatabaseVulnerabilityAssessment') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseVulnerabilityAssessment") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -175,7 +257,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -183,10 +266,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -194,18 +276,17 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('DatabaseVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessment", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DatabaseVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -219,35 +300,30 @@ async def delete( # pylint: disable=inconsistent-return-statements """Removes the database's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the database for which the vulnerability assessment is - defined. + defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -255,7 +331,7 @@ async def delete( # pylint: disable=inconsistent-return-statements vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -263,10 +339,9 @@ async def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -276,57 +351,48 @@ async def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.DatabaseVulnerabilityAssessmentListResult]: + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.DatabaseVulnerabilityAssessment"]: """Lists the vulnerability assessments of a managed database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the database for which the vulnerability assessment is - defined. + defined. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseVulnerabilityAssessmentListResult or the - result of cls(response) + :return: An iterator like instance of either DatabaseVulnerabilityAssessment or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -334,17 +400,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -360,10 +416,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -373,8 +427,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_databases_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_databases_operations.py index 608e4f0084423..2f2a8ac23f96d 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_databases_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_databases_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,23 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_databases_operations import build_complete_restore_request_initial, build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_instance_request, build_list_inaccessible_by_instance_request, build_update_request_initial -T = TypeVar('T') +from ...operations._managed_databases_operations import ( + build_cancel_move_request, + build_complete_move_request, + build_complete_restore_request, + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_instance_request, + build_list_inaccessible_by_instance_request, + build_start_move_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedDatabasesOperations: """ .. warning:: @@ -45,50 +64,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedDatabaseListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedDatabase"]: """Gets a list of managed databases. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedDatabaseListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedDatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedDatabase or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -96,16 +105,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -121,10 +121,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -134,56 +132,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any ) -> _models.ManagedDatabase: """Gets a managed database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedDatabase, or the result of cls(response) + :return: ManagedDatabase or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedDatabase - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabase] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabase] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -191,49 +177,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedDatabase', pipeline_response) + deserialized = self._deserialize("ManagedDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, database_name: str, - parameters: _models.ManagedDatabase, + parameters: Union[_models.ManagedDatabase, IO], **kwargs: Any ) -> Optional[_models.ManagedDatabase]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedDatabase]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedDatabase]] - _json = self._serialize.body(parameters, 'ManagedDatabase') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedDatabase") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, @@ -241,7 +229,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -249,10 +238,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -261,42 +249,120 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedDatabase', pipeline_response) + deserialized = self._deserialize("ManagedDatabase", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedDatabase', pipeline_response) + deserialized = self._deserialize("ManagedDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, database_name: str, parameters: _models.ManagedDatabase, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ManagedDatabase]: """Creates a new database or updates an existing database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The requested database resource state. + :param parameters: The requested database resource state. Required. :type parameters: ~azure.mgmt.sql.models.ManagedDatabase - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ManagedDatabase or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedDatabase]: + """Creates a new database or updates an existing database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested database resource state. Required. + :type parameters: IO + :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 ManagedDatabase or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.ManagedDatabase, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedDatabase]: + """Creates a new database or updates an existing database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested database resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabase 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 @@ -308,20 +374,17 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either ManagedDatabase or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedDatabase] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabase] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabase] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -330,66 +393,55 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedDatabase', pipeline_response) + deserialized = self._deserialize("ManagedDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -397,10 +449,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -410,29 +461,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes a managed database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -443,80 +486,77 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore async def _update_initial( self, resource_group_name: str, managed_instance_name: str, database_name: str, - parameters: _models.ManagedDatabaseUpdate, + parameters: Union[_models.ManagedDatabaseUpdate, IO], **kwargs: Any ) -> Optional[_models.ManagedDatabase]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedDatabase]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedDatabase]] - _json = self._serialize.body(parameters, 'ManagedDatabaseUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedDatabaseUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, @@ -524,7 +564,8 @@ async def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -532,10 +573,9 @@ async def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -544,39 +584,117 @@ async def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedDatabase', pipeline_response) + deserialized = self._deserialize("ManagedDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_update( self, resource_group_name: str, managed_instance_name: str, database_name: str, parameters: _models.ManagedDatabaseUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ManagedDatabase]: """Updates an existing database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The requested database resource state. + :param parameters: The requested database resource state. Required. :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseUpdate - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ManagedDatabase or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedDatabase]: + """Updates an existing database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested database resource state. Required. + :type parameters: IO + :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 ManagedDatabase or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.ManagedDatabaseUpdate, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedDatabase]: + """Updates an existing database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested database resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseUpdate 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 @@ -588,20 +706,17 @@ async def begin_update( :return: An instance of AsyncLROPoller that returns either ManagedDatabase or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedDatabase] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabase] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabase] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -610,63 +725,63 @@ async def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedDatabase', pipeline_response) + deserialized = self._deserialize("ManagedDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore - async def _complete_restore_initial( # pylint: disable=inconsistent-return-statements + async def _cancel_move_initial( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, managed_instance_name: str, database_name: str, - parameters: _models.CompleteDatabaseRestoreDefinition, + parameters: Union[_models.ManagedDatabaseMoveDefinition, IO], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'CompleteDatabaseRestoreDefinition') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedDatabaseMoveDefinition") - request = build_complete_restore_request_initial( + request = build_cancel_move_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, @@ -674,7 +789,8 @@ async def _complete_restore_initial( # pylint: disable=inconsistent-return-stat api_version=api_version, content_type=content_type, json=_json, - template_url=self._complete_restore_initial.metadata['url'], + content=_content, + template_url=self._cancel_move_initial.metadata["url"], headers=_headers, params=_params, ) @@ -682,10 +798,9 @@ async def _complete_restore_initial( # pylint: disable=inconsistent-return-stat request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -695,32 +810,108 @@ async def _complete_restore_initial( # pylint: disable=inconsistent-return-stat if cls: return cls(pipeline_response, None, {}) - _complete_restore_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/completeRestore"} # type: ignore + _cancel_move_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/cancelMove"} # type: ignore + + @overload + async def begin_cancel_move( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: _models.ManagedDatabaseMoveDefinition, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Cancels a managed database move operation. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters of the cancel managed database move operation. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseMoveDefinition + :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: + """ + + @overload + async def begin_cancel_move( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Cancels a managed database move operation. + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters of the cancel managed database move operation. Required. + :type parameters: IO + :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: + """ @distributed_trace_async - async def begin_complete_restore( # pylint: disable=inconsistent-return-statements + async def begin_cancel_move( self, resource_group_name: str, managed_instance_name: str, database_name: str, - parameters: _models.CompleteDatabaseRestoreDefinition, + parameters: Union[_models.ManagedDatabaseMoveDefinition, IO], **kwargs: Any ) -> AsyncLROPoller[None]: - """Completes the restore operation on a managed database. + """Cancels a managed database move operation. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The definition for completing the restore of this managed database. - :type parameters: ~azure.mgmt.sql.models.CompleteDatabaseRestoreDefinition - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :param parameters: Parameters of the cancel managed database move operation. Is either a model + type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseMoveDefinition 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 @@ -731,123 +922,742 @@ async def begin_complete_restore( # pylint: disable=inconsistent-return-stateme 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + 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] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: - raw_result = await self._complete_restore_initial( # type: ignore + raw_result = await self._cancel_move_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_complete_restore.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/completeRestore"} # type: ignore + begin_cancel_move.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/cancelMove"} # type: ignore - @distributed_trace - def list_inaccessible_by_instance( + async def _complete_move_initial( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, managed_instance_name: str, + database_name: str, + parameters: Union[_models.ManagedDatabaseMoveDefinition, IO], **kwargs: Any - ) -> AsyncIterable[_models.ManagedDatabaseListResult]: - """Gets a list of inaccessible managed databases in a managed instance. + ) -> None: + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. - :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. - :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedDatabaseListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedDatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError - """ - _headers = kwargs.pop("headers", {}) or {} + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) - def prepare_request(next_link=None): - if not next_link: - - request = build_list_inaccessible_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.list_inaccessible_by_instance.metadata['url'], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedDatabaseMoveDefinition") - else: - - request = build_list_inaccessible_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" + request = build_complete_move_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self._complete_move_initial.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _complete_move_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/completeMove"} # type: ignore + + @overload + async def begin_complete_move( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: _models.ManagedDatabaseMoveDefinition, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Completes a managed database move operation. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters of the complete managed database move operation. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseMoveDefinition + :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: + """ + + @overload + async def begin_complete_move( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Completes a managed database move operation. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters of the complete managed database move operation. Required. + :type parameters: IO + :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: + """ + + @distributed_trace_async + async def begin_complete_move( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.ManagedDatabaseMoveDefinition, IO], + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Completes a managed database move operation. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters of the complete managed database move operation. Is either a + model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseMoveDefinition 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. + :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: + """ + _headers = case_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: str + 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] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + if cont_token is None: + raw_result = await self._complete_move_initial( # type: ignore + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements + if cls: + return cls(pipeline_response, None, {}) + + if polling is True: + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling + if cont_token: + return AsyncLROPoller.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_complete_move.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/completeMove"} # type: ignore + + async def _complete_restore_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.CompleteDatabaseRestoreDefinition, IO], + **kwargs: Any + ) -> None: + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_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: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "CompleteDatabaseRestoreDefinition") + + request = build_complete_restore_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self._complete_restore_initial.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _complete_restore_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/completeRestore"} # type: ignore + + @overload + async def begin_complete_restore( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: _models.CompleteDatabaseRestoreDefinition, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Completes the restore operation on a managed database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The definition for completing the restore of this managed database. + Required. + :type parameters: ~azure.mgmt.sql.models.CompleteDatabaseRestoreDefinition + :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: + """ + + @overload + async def begin_complete_restore( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Completes the restore operation on a managed database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The definition for completing the restore of this managed database. + Required. + :type parameters: IO + :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: + """ + + @distributed_trace_async + async def begin_complete_restore( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.CompleteDatabaseRestoreDefinition, IO], + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Completes the restore operation on a managed database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The definition for completing the restore of this managed database. Is + either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.CompleteDatabaseRestoreDefinition 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. + :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: + """ + _headers = case_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: str + 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] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + if cont_token is None: + raw_result = await self._complete_restore_initial( # type: ignore + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements + if cls: + return cls(pipeline_response, None, {}) + + if polling is True: + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling + if cont_token: + return AsyncLROPoller.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_complete_restore.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/completeRestore"} # type: ignore + + async def _start_move_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.ManagedDatabaseStartMoveDefinition, IO], + **kwargs: Any + ) -> None: + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_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: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedDatabaseStartMoveDefinition") + + request = build_start_move_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self._start_move_initial.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _start_move_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/startMove"} # type: ignore + + @overload + async def begin_start_move( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: _models.ManagedDatabaseStartMoveDefinition, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Starts a managed database move operation. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters of the start managed database move operation. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseStartMoveDefinition + :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: + """ + + @overload + async def begin_start_move( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Starts a managed database move operation. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters of the start managed database move operation. Required. + :type parameters: IO + :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: + """ + + @distributed_trace_async + async def begin_start_move( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.ManagedDatabaseStartMoveDefinition, IO], + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Starts a managed database move operation. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters of the start managed database move operation. Is either a model + type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseStartMoveDefinition 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. + :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: + """ + _headers = case_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: str + 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] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + if cont_token is None: + raw_result = await self._start_move_initial( # type: ignore + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements + if cls: + return cls(pipeline_response, None, {}) + + if polling is True: + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling + if cont_token: + return AsyncLROPoller.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_move.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/startMove"} # type: ignore + + @distributed_trace + def list_inaccessible_by_instance( + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedDatabase"]: + """Gets a list of inaccessible managed databases in a managed instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ManagedDatabase or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _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: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_list_inaccessible_by_instance_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_inaccessible_by_instance.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + else: + request = HttpRequest("GET", next_link) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + request.method = "GET" return request async def extract_data(pipeline_response): @@ -860,10 +1670,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -873,8 +1681,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_inaccessible_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/inaccessibleManagedDatabases"} # type: ignore + list_inaccessible_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/inaccessibleManagedDatabases"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_administrators_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_administrators_operations.py index ab20be9df51c9..50a4f92be6d44 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_administrators_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_administrators_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_instance_administrators_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_instance_request -T = TypeVar('T') +from ...operations._managed_instance_administrators_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_instance_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedInstanceAdministratorsOperations: """ .. warning:: @@ -45,50 +58,42 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstanceAdministratorListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedInstanceAdministrator"]: """Gets a list of managed instance administrators. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceAdministratorListResult or the - result of cls(response) + :return: An iterator like instance of either ManagedInstanceAdministrator or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceAdministratorListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceAdministrator] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceAdministratorListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAdministratorListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -96,16 +101,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -121,10 +117,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -134,11 +128,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators"} # type: ignore @distributed_trace_async async def get( @@ -151,39 +143,33 @@ async def get( """Gets a managed instance administrator. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param administrator_name: + :param administrator_name: "ActiveDirectory" Required. :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceAdministrator, or the result of cls(response) + :return: ManagedInstanceAdministrator or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceAdministrator - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceAdministrator] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAdministrator] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, administrator_name=administrator_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -191,49 +177,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceAdministrator', pipeline_response) + deserialized = self._deserialize("ManagedInstanceAdministrator", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, administrator_name: Union[str, "_models.AdministratorName"], - parameters: _models.ManagedInstanceAdministrator, + parameters: Union[_models.ManagedInstanceAdministrator, IO], **kwargs: Any ) -> Optional[_models.ManagedInstanceAdministrator]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedInstanceAdministrator]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstanceAdministrator]] - _json = self._serialize.body(parameters, 'ManagedInstanceAdministrator') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceAdministrator") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, administrator_name=administrator_name, @@ -241,7 +229,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -249,10 +238,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -261,42 +249,43 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedInstanceAdministrator', pipeline_response) + deserialized = self._deserialize("ManagedInstanceAdministrator", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedInstanceAdministrator', pipeline_response) + deserialized = self._deserialize("ManagedInstanceAdministrator", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, administrator_name: Union[str, "_models.AdministratorName"], parameters: _models.ManagedInstanceAdministrator, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ManagedInstanceAdministrator]: """Creates or updates a managed instance administrator. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param administrator_name: + :param administrator_name: "ActiveDirectory" Required. :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName - :param parameters: The requested administrator parameters. + :param parameters: The requested administrator parameters. Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstanceAdministrator - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -308,20 +297,94 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either ManagedInstanceAdministrator or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceAdministrator] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + administrator_name: Union[str, "_models.AdministratorName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstanceAdministrator]: + """Creates or updates a managed instance administrator. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param administrator_name: "ActiveDirectory" Required. + :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName + :param parameters: The requested administrator parameters. Required. + :type parameters: IO + :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 ManagedInstanceAdministrator or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceAdministrator] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + administrator_name: Union[str, "_models.AdministratorName"], + parameters: Union[_models.ManagedInstanceAdministrator, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstanceAdministrator]: + """Creates or updates a managed instance administrator. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param administrator_name: "ActiveDirectory" Required. + :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName + :param parameters: The requested administrator parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceAdministrator 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. + :return: An instance of AsyncLROPoller that returns either ManagedInstanceAdministrator or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceAdministrator] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceAdministrator] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAdministrator] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -330,39 +393,35 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedInstanceAdministrator', pipeline_response) + deserialized = self._deserialize("ManagedInstanceAdministrator", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements self, @@ -371,25 +430,22 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements administrator_name: Union[str, "_models.AdministratorName"], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, administrator_name=administrator_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -397,10 +453,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -410,11 +465,10 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements + async def begin_delete( self, resource_group_name: str, managed_instance_name: str, @@ -424,15 +478,12 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements """Deletes a managed instance administrator. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param administrator_name: + :param administrator_name: "ActiveDirectory" Required. :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -443,53 +494,46 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, administrator_name=administrator_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_advanced_threat_protection_settings_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_advanced_threat_protection_settings_operations.py new file mode 100644 index 0000000000000..f7ec46eb3c169 --- /dev/null +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_advanced_threat_protection_settings_operations.py @@ -0,0 +1,431 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.core.utils import case_insensitive_dict +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._managed_instance_advanced_threat_protection_settings_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_instance_request, +) + +T = TypeVar("T") +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + + +class ManagedInstanceAdvancedThreatProtectionSettingsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.mgmt.sql.aio.SqlManagementClient`'s + :attr:`managed_instance_advanced_threat_protection_settings` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs) -> None: + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace + def list_by_instance( + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedInstanceAdvancedThreatProtection"]: + """Get the managed instance's Advanced Threat Protection settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ManagedInstanceAdvancedThreatProtection or the + result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _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: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAdvancedThreatProtectionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_instance_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_instance.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + else: + request = HttpRequest("GET", next_link) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("ManagedInstanceAdvancedThreatProtectionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/advancedThreatProtectionSettings"} # type: ignore + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + managed_instance_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + **kwargs: Any + ) -> _models.ManagedInstanceAdvancedThreatProtection: + """Get a managed instance's Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ManagedInstanceAdvancedThreatProtection or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedInstanceAdvancedThreatProtection + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + _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: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAdvancedThreatProtection] + + request = build_get_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + advanced_threat_protection_name=advanced_threat_protection_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 + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("ManagedInstanceAdvancedThreatProtection", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore + + async def _create_or_update_initial( + self, + resource_group_name: str, + managed_instance_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: Union[_models.ManagedInstanceAdvancedThreatProtection, IO], + **kwargs: Any + ) -> Optional[_models.ManagedInstanceAdvancedThreatProtection]: + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_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: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstanceAdvancedThreatProtection]] + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceAdvancedThreatProtection") + + request = build_create_or_update_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + advanced_threat_protection_name=advanced_threat_protection_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + 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 + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize("ManagedInstanceAdvancedThreatProtection", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: _models.ManagedInstanceAdvancedThreatProtection, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstanceAdvancedThreatProtection]: + """Creates or updates Advanced Threat Protection settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The managed instance Advanced Threat Protection state. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceAdvancedThreatProtection + :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 + ManagedInstanceAdvancedThreatProtection or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstanceAdvancedThreatProtection]: + """Creates or updates Advanced Threat Protection settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The managed instance Advanced Threat Protection state. Required. + :type parameters: IO + :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 + ManagedInstanceAdvancedThreatProtection or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: Union[_models.ManagedInstanceAdvancedThreatProtection, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstanceAdvancedThreatProtection]: + """Creates or updates Advanced Threat Protection settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The managed instance Advanced Threat Protection state. Is either a model + type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceAdvancedThreatProtection 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. + :return: An instance of AsyncLROPoller that returns either + ManagedInstanceAdvancedThreatProtection or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = case_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: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAdvancedThreatProtection] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + if cont_token is None: + raw_result = await self._create_or_update_initial( # type: ignore + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + advanced_threat_protection_name=advanced_threat_protection_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): + deserialized = self._deserialize("ManagedInstanceAdvancedThreatProtection", pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + if polling is True: + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling + if cont_token: + return AsyncLROPoller.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.Sql/managedInstances/{managedInstanceName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_azure_ad_only_authentications_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_azure_ad_only_authentications_operations.py index c45bc897ce7fc..20ade792e661b 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_azure_ad_only_authentications_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_azure_ad_only_authentications_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_instance_azure_ad_only_authentications_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_instance_request -T = TypeVar('T') +from ...operations._managed_instance_azure_ad_only_authentications_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_instance_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedInstanceAzureADOnlyAuthenticationsOperations: """ .. warning:: @@ -45,7 +58,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -57,39 +69,34 @@ async def get( """Gets a specific Azure Active Directory only authentication property. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceAzureADOnlyAuthentication, or the result of cls(response) + :return: ManagedInstanceAzureADOnlyAuthentication or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceAzureADOnlyAuthentication - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceAzureADOnlyAuthentication] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAzureADOnlyAuthentication] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, authentication_name=authentication_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,49 +104,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceAzureADOnlyAuthentication', pipeline_response) + deserialized = self._deserialize("ManagedInstanceAzureADOnlyAuthentication", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, authentication_name: Union[str, "_models.AuthenticationName"], - parameters: _models.ManagedInstanceAzureADOnlyAuthentication, + parameters: Union[_models.ManagedInstanceAzureADOnlyAuthentication, IO], **kwargs: Any ) -> Optional[_models.ManagedInstanceAzureADOnlyAuthentication]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedInstanceAzureADOnlyAuthentication]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstanceAzureADOnlyAuthentication]] - _json = self._serialize.body(parameters, 'ManagedInstanceAzureADOnlyAuthentication') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceAzureADOnlyAuthentication") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, authentication_name=authentication_name, @@ -147,7 +156,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -155,10 +165,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -167,44 +176,130 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedInstanceAzureADOnlyAuthentication', pipeline_response) + deserialized = self._deserialize("ManagedInstanceAzureADOnlyAuthentication", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedInstanceAzureADOnlyAuthentication', pipeline_response) + deserialized = self._deserialize("ManagedInstanceAzureADOnlyAuthentication", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, authentication_name: Union[str, "_models.AuthenticationName"], parameters: _models.ManagedInstanceAzureADOnlyAuthentication, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ManagedInstanceAzureADOnlyAuthentication]: """Sets Server Active Directory only authentication property or updates an existing server Active Directory only authentication property. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName :param parameters: The required parameters for creating or updating an Active Directory only - authentication property. + authentication property. Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstanceAzureADOnlyAuthentication - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 + ManagedInstanceAzureADOnlyAuthentication or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceAzureADOnlyAuthentication] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + authentication_name: Union[str, "_models.AuthenticationName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstanceAzureADOnlyAuthentication]: + """Sets Server Active Directory only authentication property or updates an existing server Active + Directory only authentication property. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. + :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName + :param parameters: The required parameters for creating or updating an Active Directory only + authentication property. Required. + :type parameters: IO + :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 + ManagedInstanceAzureADOnlyAuthentication or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceAzureADOnlyAuthentication] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + authentication_name: Union[str, "_models.AuthenticationName"], + parameters: Union[_models.ManagedInstanceAzureADOnlyAuthentication, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstanceAzureADOnlyAuthentication]: + """Sets Server Active Directory only authentication property or updates an existing server Active + Directory only authentication property. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. + :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName + :param parameters: The required parameters for creating or updating an Active Directory only + authentication property. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceAzureADOnlyAuthentication 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 @@ -217,20 +312,17 @@ async def begin_create_or_update( ManagedInstanceAzureADOnlyAuthentication or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceAzureADOnlyAuthentication] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceAzureADOnlyAuthentication] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAzureADOnlyAuthentication] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -239,39 +331,35 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedInstanceAzureADOnlyAuthentication', pipeline_response) + deserialized = self._deserialize("ManagedInstanceAzureADOnlyAuthentication", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements self, @@ -280,25 +368,22 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements authentication_name: Union[str, "_models.AuthenticationName"], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, authentication_name=authentication_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -306,10 +391,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -319,11 +403,10 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements + async def begin_delete( self, resource_group_name: str, managed_instance_name: str, @@ -333,15 +416,13 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements """Deletes an existing server Active Directory only authentication property. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -352,100 +433,86 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, authentication_name=authentication_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstanceAzureADOnlyAuthListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedInstanceAzureADOnlyAuthentication"]: """Gets a list of server Azure Active Directory only authentications. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceAzureADOnlyAuthListResult or the + :return: An iterator like instance of either ManagedInstanceAzureADOnlyAuthentication or the result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceAzureADOnlyAuthListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceAzureADOnlyAuthentication] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceAzureADOnlyAuthListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAzureADOnlyAuthListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -453,16 +520,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -478,10 +536,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -491,8 +547,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_dtcs_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_dtcs_operations.py new file mode 100644 index 0000000000000..2421d3c20b566 --- /dev/null +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_dtcs_operations.py @@ -0,0 +1,416 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.core.utils import case_insensitive_dict +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._managed_instance_dtcs_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_managed_instance_request, +) + +T = TypeVar("T") +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + + +class ManagedInstanceDtcsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.mgmt.sql.aio.SqlManagementClient`'s + :attr:`managed_instance_dtcs` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs) -> None: + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace + def list_by_managed_instance( + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedInstanceDtc"]: + """Gets a list of managed instance DTC settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ManagedInstanceDtc or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceDtc] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _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: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceDtcListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_managed_instance_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_managed_instance.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + else: + request = HttpRequest("GET", next_link) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("ManagedInstanceDtcListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + list_by_managed_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dtc"} # type: ignore + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + managed_instance_name: str, + dtc_name: Union[str, "_models.DtcName"], + **kwargs: Any + ) -> _models.ManagedInstanceDtc: + """Gets managed instance DTC settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param dtc_name: The name of the managed instance DTC. "current" Required. + :type dtc_name: str or ~azure.mgmt.sql.models.DtcName + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ManagedInstanceDtc or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedInstanceDtc + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + _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: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceDtc] + + request = build_get_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + dtc_name=dtc_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 + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("ManagedInstanceDtc", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dtc/{dtcName}"} # type: ignore + + async def _create_or_update_initial( + self, + resource_group_name: str, + managed_instance_name: str, + dtc_name: Union[str, "_models.DtcName"], + parameters: Union[_models.ManagedInstanceDtc, IO], + **kwargs: Any + ) -> _models.ManagedInstanceDtc: + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_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: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceDtc] + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceDtc") + + request = build_create_or_update_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + dtc_name=dtc_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + 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 + + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("ManagedInstanceDtc", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dtc/{dtcName}"} # type: ignore + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + dtc_name: Union[str, "_models.DtcName"], + parameters: _models.ManagedInstanceDtc, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstanceDtc]: + """Updates managed instance DTC settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param dtc_name: The name of the managed instance DTC. "current" Required. + :type dtc_name: str or ~azure.mgmt.sql.models.DtcName + :param parameters: Managed instance DTC settings. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceDtc + :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 ManagedInstanceDtc or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceDtc] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + dtc_name: Union[str, "_models.DtcName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstanceDtc]: + """Updates managed instance DTC settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param dtc_name: The name of the managed instance DTC. "current" Required. + :type dtc_name: str or ~azure.mgmt.sql.models.DtcName + :param parameters: Managed instance DTC settings. Required. + :type parameters: IO + :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 ManagedInstanceDtc or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceDtc] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + dtc_name: Union[str, "_models.DtcName"], + parameters: Union[_models.ManagedInstanceDtc, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstanceDtc]: + """Updates managed instance DTC settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param dtc_name: The name of the managed instance DTC. "current" Required. + :type dtc_name: str or ~azure.mgmt.sql.models.DtcName + :param parameters: Managed instance DTC settings. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceDtc 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. + :return: An instance of AsyncLROPoller that returns either ManagedInstanceDtc or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceDtc] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = case_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: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceDtc] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + if cont_token is None: + raw_result = await self._create_or_update_initial( # type: ignore + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + dtc_name=dtc_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): + deserialized = self._deserialize("ManagedInstanceDtc", pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + if polling is True: + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling + if cont_token: + return AsyncLROPoller.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.Sql/managedInstances/{managedInstanceName}/dtc/{dtcName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_encryption_protectors_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_encryption_protectors_operations.py index 696b11e285aa0..63a3ed594ea6b 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_encryption_protectors_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_encryption_protectors_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_instance_encryption_protectors_operations import build_create_or_update_request_initial, build_get_request, build_list_by_instance_request, build_revalidate_request_initial -T = TypeVar('T') +from ...operations._managed_instance_encryption_protectors_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_instance_request, + build_revalidate_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedInstanceEncryptionProtectorsOperations: """ .. warning:: @@ -45,7 +58,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - async def _revalidate_initial( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, @@ -53,25 +65,22 @@ async def _revalidate_initial( # pylint: disable=inconsistent-return-statements encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_revalidate_request_initial( + request = build_revalidate_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, encryption_protector_name=encryption_protector_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._revalidate_initial.metadata['url'], + template_url=self._revalidate_initial.metadata["url"], headers=_headers, params=_params, ) @@ -79,10 +88,9 @@ async def _revalidate_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -92,11 +100,10 @@ async def _revalidate_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _revalidate_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}/revalidate"} # type: ignore - + _revalidate_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}/revalidate"} # type: ignore @distributed_trace_async - async def begin_revalidate( # pylint: disable=inconsistent-return-statements + async def begin_revalidate( self, resource_group_name: str, managed_instance_name: str, @@ -106,15 +113,13 @@ async def begin_revalidate( # pylint: disable=inconsistent-return-statements """Revalidates an existing encryption protector. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param encryption_protector_name: The name of the encryption protector to be updated. + :param encryption_protector_name: The name of the encryption protector to be updated. "current" + Required. :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -125,100 +130,86 @@ async def begin_revalidate( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._revalidate_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, encryption_protector_name=encryption_protector_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_revalidate.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}/revalidate"} # type: ignore + begin_revalidate.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}/revalidate"} # type: ignore @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstanceEncryptionProtectorListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedInstanceEncryptionProtector"]: """Gets a list of managed instance encryption protectors. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceEncryptionProtectorListResult or - the result of cls(response) + :return: An iterator like instance of either ManagedInstanceEncryptionProtector or the result + of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceEncryptionProtectorListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceEncryptionProtector] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceEncryptionProtectorListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceEncryptionProtectorListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -226,16 +217,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -251,10 +233,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -264,11 +244,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector"} # type: ignore @distributed_trace_async async def get( @@ -281,39 +259,34 @@ async def get( """Gets a managed instance encryption protector. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param encryption_protector_name: The name of the encryption protector to be retrieved. + "current" Required. :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceEncryptionProtector, or the result of cls(response) + :return: ManagedInstanceEncryptionProtector or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceEncryptionProtector - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceEncryptionProtector] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceEncryptionProtector] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, encryption_protector_name=encryption_protector_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -321,49 +294,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceEncryptionProtector', pipeline_response) + deserialized = self._deserialize("ManagedInstanceEncryptionProtector", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], - parameters: _models.ManagedInstanceEncryptionProtector, + parameters: Union[_models.ManagedInstanceEncryptionProtector, IO], **kwargs: Any ) -> Optional[_models.ManagedInstanceEncryptionProtector]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedInstanceEncryptionProtector]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstanceEncryptionProtector]] - _json = self._serialize.body(parameters, 'ManagedInstanceEncryptionProtector') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceEncryptionProtector") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, encryption_protector_name=encryption_protector_name, @@ -371,7 +346,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -379,10 +355,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -391,39 +366,122 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedInstanceEncryptionProtector', pipeline_response) + deserialized = self._deserialize("ManagedInstanceEncryptionProtector", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], parameters: _models.ManagedInstanceEncryptionProtector, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ManagedInstanceEncryptionProtector]: """Updates an existing encryption protector. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param encryption_protector_name: The name of the encryption protector to be updated. + :param encryption_protector_name: The name of the encryption protector to be updated. "current" + Required. :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName - :param parameters: The requested encryption protector resource state. + :param parameters: The requested encryption protector resource state. Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstanceEncryptionProtector - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ManagedInstanceEncryptionProtector + or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceEncryptionProtector] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstanceEncryptionProtector]: + """Updates an existing encryption protector. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param encryption_protector_name: The name of the encryption protector to be updated. "current" + Required. + :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName + :param parameters: The requested encryption protector resource state. Required. + :type parameters: IO + :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 ManagedInstanceEncryptionProtector + or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceEncryptionProtector] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], + parameters: Union[_models.ManagedInstanceEncryptionProtector, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstanceEncryptionProtector]: + """Updates an existing encryption protector. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param encryption_protector_name: The name of the encryption protector to be updated. "current" + Required. + :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName + :param parameters: The requested encryption protector resource state. Is either a model type or + a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceEncryptionProtector 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 @@ -436,20 +494,17 @@ async def begin_create_or_update( or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceEncryptionProtector] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceEncryptionProtector] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceEncryptionProtector] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -458,36 +513,32 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedInstanceEncryptionProtector', pipeline_response) + deserialized = self._deserialize("ManagedInstanceEncryptionProtector", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_keys_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_keys_operations.py index 747d67d749308..06a4254faef4a 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_keys_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_keys_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_instance_keys_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_instance_request -T = TypeVar('T') +from ...operations._managed_instance_keys_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_instance_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedInstanceKeysOperations: """ .. warning:: @@ -45,55 +58,44 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - filter: Optional[str] = None, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstanceKeyListResult]: + self, resource_group_name: str, managed_instance_name: str, filter: Optional[str] = None, **kwargs: Any + ) -> AsyncIterable["_models.ManagedInstanceKey"]: """Gets a list of managed instance keys. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceKeyListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceKeyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedInstanceKey or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceKey] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceKeyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceKeyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, - api_version=api_version, filter=filter, - template_url=self.list_by_instance.metadata['url'], + api_version=api_version, + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -101,17 +103,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -127,10 +119,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -140,56 +130,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - managed_instance_name: str, - key_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, key_name: str, **kwargs: Any ) -> _models.ManagedInstanceKey: """Gets a managed instance key. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param key_name: The name of the managed instance key to be retrieved. + :param key_name: The name of the managed instance key to be retrieved. Required. :type key_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceKey, or the result of cls(response) + :return: ManagedInstanceKey or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceKey - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceKey] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceKey] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, key_name=key_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -197,49 +175,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceKey', pipeline_response) + deserialized = self._deserialize("ManagedInstanceKey", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, key_name: str, - parameters: _models.ManagedInstanceKey, + parameters: Union[_models.ManagedInstanceKey, IO], **kwargs: Any ) -> Optional[_models.ManagedInstanceKey]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedInstanceKey]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstanceKey]] - _json = self._serialize.body(parameters, 'ManagedInstanceKey') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceKey") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, key_name=key_name, @@ -247,7 +227,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -255,10 +236,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -267,42 +247,44 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedInstanceKey', pipeline_response) + deserialized = self._deserialize("ManagedInstanceKey", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedInstanceKey', pipeline_response) + deserialized = self._deserialize("ManagedInstanceKey", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, key_name: str, parameters: _models.ManagedInstanceKey, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ManagedInstanceKey]: """Creates or updates a managed instance key. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param key_name: The name of the managed instance key to be operated on (updated or created). + Required. :type key_name: str - :param parameters: The requested managed instance key resource state. + :param parameters: The requested managed instance key resource state. Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstanceKey - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -314,20 +296,96 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either ManagedInstanceKey or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceKey] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + key_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstanceKey]: + """Creates or updates a managed instance key. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param key_name: The name of the managed instance key to be operated on (updated or created). + Required. + :type key_name: str + :param parameters: The requested managed instance key resource state. Required. + :type parameters: IO + :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 ManagedInstanceKey or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceKey] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + key_name: str, + parameters: Union[_models.ManagedInstanceKey, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstanceKey]: + """Creates or updates a managed instance key. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param key_name: The name of the managed instance key to be operated on (updated or created). + Required. + :type key_name: str + :param parameters: The requested managed instance key resource state. Is either a model type or + a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceKey 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. + :return: An instance of AsyncLROPoller that returns either ManagedInstanceKey or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceKey] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceKey] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceKey] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -336,66 +394,55 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedInstanceKey', pipeline_response) + deserialized = self._deserialize("ManagedInstanceKey", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - key_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, key_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, key_name=key_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -403,10 +450,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -416,29 +462,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - key_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, managed_instance_name: str, key_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes the managed instance key with the given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param key_name: The name of the managed instance key to be deleted. + :param key_name: The name of the managed instance key to be deleted. Required. :type key_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -449,53 +487,46 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, key_name=key_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_long_term_retention_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_long_term_retention_policies_operations.py index 2f099efd3d3b6..5a0f47bd17602 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_long_term_retention_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_long_term_retention_policies_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_instance_long_term_retention_policies_operations import build_create_or_update_request_initial, build_get_request, build_list_by_database_request -T = TypeVar('T') +from ...operations._managed_instance_long_term_retention_policies_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedInstanceLongTermRetentionPoliciesOperations: """ .. warning:: @@ -45,7 +57,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -58,34 +69,28 @@ async def get( """Gets a managed database's long term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be Default. + :param policy_name: The policy name. Should always be Default. "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicyName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceLongTermRetentionPolicy, or the result of cls(response) + :return: ManagedInstanceLongTermRetentionPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionPolicy] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -93,7 +98,7 @@ async def get( policy_name=policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -101,25 +106,23 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceLongTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedInstanceLongTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore async def _create_or_update_initial( self, @@ -127,24 +130,28 @@ async def _create_or_update_initial( managed_instance_name: str, database_name: str, policy_name: Union[str, "_models.ManagedInstanceLongTermRetentionPolicyName"], - parameters: _models.ManagedInstanceLongTermRetentionPolicy, + parameters: Union[_models.ManagedInstanceLongTermRetentionPolicy, IO], **kwargs: Any ) -> Optional[_models.ManagedInstanceLongTermRetentionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedInstanceLongTermRetentionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstanceLongTermRetentionPolicy]] - _json = self._serialize.body(parameters, 'ManagedInstanceLongTermRetentionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceLongTermRetentionPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, @@ -153,7 +160,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -161,10 +169,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -173,17 +180,16 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedInstanceLongTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedInstanceLongTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, @@ -191,24 +197,26 @@ async def begin_create_or_update( database_name: str, policy_name: Union[str, "_models.ManagedInstanceLongTermRetentionPolicyName"], parameters: _models.ManagedInstanceLongTermRetentionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ManagedInstanceLongTermRetentionPolicy]: """Sets a managed database's long term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be Default. + :param policy_name: The policy name. Should always be Default. "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicyName - :param parameters: The long term retention policy info. + :param parameters: The long term retention policy info. Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -221,20 +229,102 @@ async def begin_create_or_update( ManagedInstanceLongTermRetentionPolicy or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + policy_name: Union[str, "_models.ManagedInstanceLongTermRetentionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstanceLongTermRetentionPolicy]: + """Sets a managed database's long term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be Default. "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicyName + :param parameters: The long term retention policy info. Required. + :type parameters: IO + :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 + ManagedInstanceLongTermRetentionPolicy or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + policy_name: Union[str, "_models.ManagedInstanceLongTermRetentionPolicyName"], + parameters: Union[_models.ManagedInstanceLongTermRetentionPolicy, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstanceLongTermRetentionPolicy]: + """Sets a managed database's long term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be Default. "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicyName + :param parameters: The long term retention policy info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicy 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. + :return: An instance of AsyncLROPoller that returns either + ManagedInstanceLongTermRetentionPolicy or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -244,87 +334,75 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedInstanceLongTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedInstanceLongTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstanceLongTermRetentionPolicyListResult]: + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedInstanceLongTermRetentionPolicy"]: """Gets a database's long term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceLongTermRetentionPolicyListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstanceLongTermRetentionPolicy or the + result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -332,17 +410,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -358,10 +426,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -371,8 +437,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_operations_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_operations_operations.py index 123321d08f244..d88b6e5846bd9 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_operations_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_operations_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_instance_operations_operations import build_cancel_request, build_get_request, build_list_by_managed_instance_request -T = TypeVar('T') +from ...operations._managed_instance_operations_operations import ( + build_cancel_request, + build_get_request, + build_list_by_managed_instance_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedInstanceOperationsOperations: """ .. warning:: @@ -43,50 +55,42 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_managed_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstanceOperationListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedInstanceOperation"]: """Gets a list of operations performed on the managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceOperationListResult or the result - of cls(response) + :return: An iterator like instance of either ManagedInstanceOperation or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceOperationListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceOperation] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceOperationListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceOperationListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_managed_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_managed_instance.metadata['url'], + template_url=self.list_by_managed_instance.metadata["url"], headers=_headers, params=_params, ) @@ -94,16 +98,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_managed_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -119,10 +114,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -132,56 +125,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_managed_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations"} # type: ignore + list_by_managed_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - managed_instance_name: str, - operation_id: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, operation_id: str, **kwargs: Any ) -> _models.ManagedInstanceOperation: """Gets a management operation on a managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param operation_id: + :param operation_id: Required. :type operation_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceOperation, or the result of cls(response) + :return: ManagedInstanceOperation or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceOperation - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceOperation] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceOperation] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, operation_id=operation_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -189,70 +170,58 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceOperation', pipeline_response) + deserialized = self._deserialize("ManagedInstanceOperation", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations/{operationId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations/{operationId}"} # type: ignore @distributed_trace_async async def cancel( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - operation_id: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, operation_id: str, **kwargs: Any ) -> None: """Cancels the asynchronous operation on the managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param operation_id: + :param operation_id: Required. :type operation_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_cancel_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, operation_id=operation_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.cancel.metadata['url'], + template_url=self.cancel.metadata["url"], headers=_headers, params=_params, ) @@ -260,10 +229,9 @@ async def cancel( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -273,5 +241,4 @@ async def cancel( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - cancel.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations/{operationId}/cancel"} # type: ignore - + cancel.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations/{operationId}/cancel"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_private_endpoint_connections_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_private_endpoint_connections_operations.py index 788a365f1cfc6..ba54da53cd567 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_private_endpoint_connections_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_private_endpoint_connections_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_instance_private_endpoint_connections_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_managed_instance_request -T = TypeVar('T') +from ...operations._managed_instance_private_endpoint_connections_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_managed_instance_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedInstancePrivateEndpointConnectionsOperations: """ .. warning:: @@ -45,51 +58,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - resource_group_name: str, - managed_instance_name: str, - private_endpoint_connection_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, private_endpoint_connection_name: str, **kwargs: Any ) -> _models.ManagedInstancePrivateEndpointConnection: """Gets a private endpoint connection. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param private_endpoint_connection_name: The name of the private endpoint connection. + :param private_endpoint_connection_name: The name of the private endpoint connection. Required. :type private_endpoint_connection_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstancePrivateEndpointConnection, or the result of cls(response) + :return: ManagedInstancePrivateEndpointConnection or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstancePrivateEndpointConnection - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstancePrivateEndpointConnection] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstancePrivateEndpointConnection] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, private_endpoint_connection_name=private_endpoint_connection_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,49 +99,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstancePrivateEndpointConnection', pipeline_response) + deserialized = self._deserialize("ManagedInstancePrivateEndpointConnection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, private_endpoint_connection_name: str, - parameters: _models.ManagedInstancePrivateEndpointConnection, + parameters: Union[_models.ManagedInstancePrivateEndpointConnection, IO], **kwargs: Any ) -> Optional[_models.ManagedInstancePrivateEndpointConnection]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedInstancePrivateEndpointConnection]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstancePrivateEndpointConnection]] - _json = self._serialize.body(parameters, 'ManagedInstancePrivateEndpointConnection') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstancePrivateEndpointConnection") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, private_endpoint_connection_name=private_endpoint_connection_name, @@ -147,7 +151,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -155,10 +160,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -167,39 +171,80 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedInstancePrivateEndpointConnection', pipeline_response) + deserialized = self._deserialize("ManagedInstancePrivateEndpointConnection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, private_endpoint_connection_name: str, parameters: _models.ManagedInstancePrivateEndpointConnection, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ManagedInstancePrivateEndpointConnection]: """Approve or reject a private endpoint connection with a given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param private_endpoint_connection_name: + :param private_endpoint_connection_name: Required. :type private_endpoint_connection_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstancePrivateEndpointConnection - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 + ManagedInstancePrivateEndpointConnection or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstancePrivateEndpointConnection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + private_endpoint_connection_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstancePrivateEndpointConnection]: + """Approve or reject a private endpoint connection with a given name. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param private_endpoint_connection_name: Required. + :type private_endpoint_connection_name: str + :param parameters: Required. + :type parameters: IO + :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 @@ -212,20 +257,55 @@ async def begin_create_or_update( ManagedInstancePrivateEndpointConnection or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstancePrivateEndpointConnection] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + private_endpoint_connection_name: str, + parameters: Union[_models.ManagedInstancePrivateEndpointConnection, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstancePrivateEndpointConnection]: + """Approve or reject a private endpoint connection with a given name. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param private_endpoint_connection_name: Required. + :type private_endpoint_connection_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstancePrivateEndpointConnection 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. + :return: An instance of AsyncLROPoller that returns either + ManagedInstancePrivateEndpointConnection or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstancePrivateEndpointConnection] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstancePrivateEndpointConnection] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstancePrivateEndpointConnection] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -234,66 +314,55 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedInstancePrivateEndpointConnection', pipeline_response) + deserialized = self._deserialize("ManagedInstancePrivateEndpointConnection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - private_endpoint_connection_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, private_endpoint_connection_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, private_endpoint_connection_name=private_endpoint_connection_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -301,10 +370,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -314,29 +382,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - private_endpoint_connection_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, managed_instance_name: str, private_endpoint_connection_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes a private endpoint connection with a given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param private_endpoint_connection_name: + :param private_endpoint_connection_name: Required. :type private_endpoint_connection_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -347,100 +407,86 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, private_endpoint_connection_name=private_endpoint_connection_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore @distributed_trace def list_by_managed_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstancePrivateEndpointConnectionListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedInstancePrivateEndpointConnection"]: """Gets all private endpoint connections on a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstancePrivateEndpointConnectionListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstancePrivateEndpointConnection or the + result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstancePrivateEndpointConnectionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstancePrivateEndpointConnection] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstancePrivateEndpointConnectionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstancePrivateEndpointConnectionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_managed_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_managed_instance.metadata['url'], + template_url=self.list_by_managed_instance.metadata["url"], headers=_headers, params=_params, ) @@ -448,16 +494,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_managed_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -473,10 +510,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -486,8 +521,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_managed_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections"} # type: ignore + list_by_managed_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_private_link_resources_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_private_link_resources_operations.py index 4c6fb7b5bbac1..a6b8d4d615d82 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_private_link_resources_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_private_link_resources_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,15 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_instance_private_link_resources_operations import build_get_request, build_list_by_managed_instance_request -T = TypeVar('T') +from ...operations._managed_instance_private_link_resources_operations import ( + build_get_request, + build_list_by_managed_instance_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedInstancePrivateLinkResourcesOperations: """ .. warning:: @@ -43,50 +54,42 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_managed_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstancePrivateLinkListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedInstancePrivateLink"]: """Gets the private link resources for SQL server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstancePrivateLinkListResult or the result - of cls(response) + :return: An iterator like instance of either ManagedInstancePrivateLink or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstancePrivateLinkListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstancePrivateLink] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstancePrivateLinkListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstancePrivateLinkListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_managed_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_managed_instance.metadata['url'], + template_url=self.list_by_managed_instance.metadata["url"], headers=_headers, params=_params, ) @@ -94,16 +97,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_managed_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -119,10 +113,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -132,56 +124,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_managed_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateLinkResources"} # type: ignore + list_by_managed_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateLinkResources"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - managed_instance_name: str, - group_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, group_name: str, **kwargs: Any ) -> _models.ManagedInstancePrivateLink: """Gets a private link resource for SQL server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param group_name: The name of the private link resource. + :param group_name: The name of the private link resource. Required. :type group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstancePrivateLink, or the result of cls(response) + :return: ManagedInstancePrivateLink or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstancePrivateLink - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstancePrivateLink] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstancePrivateLink] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, group_name=group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -189,22 +169,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstancePrivateLink', pipeline_response) + deserialized = self._deserialize("ManagedInstancePrivateLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateLinkResources/{groupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateLinkResources/{groupName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_tde_certificates_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_tde_certificates_operations.py index 4f71a89741172..7ffe2abde8f4b 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_tde_certificates_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_tde_certificates_operations.py @@ -6,9 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar, Union, cast - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -20,10 +26,12 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_instance_tde_certificates_operations import build_create_request_initial -T = TypeVar('T') +from ...operations._managed_instance_tde_certificates_operations import build_create_request + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedInstanceTdeCertificatesOperations: """ .. warning:: @@ -43,36 +51,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - async def _create_initial( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, managed_instance_name: str, - parameters: _models.TdeCertificate, + parameters: Union[_models.TdeCertificate, IO], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'TdeCertificate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "TdeCertificate") - request = build_create_request_initial( + request = build_create_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_initial.metadata['url'], + content=_content, + template_url=self._create_initial.metadata["url"], headers=_headers, params=_params, ) @@ -80,10 +92,9 @@ async def _create_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -93,29 +104,99 @@ async def _create_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _create_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/tdeCertificates"} # type: ignore - + _create_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/tdeCertificates"} # type: ignore - @distributed_trace_async - async def begin_create( # pylint: disable=inconsistent-return-statements + @overload + async def begin_create( self, resource_group_name: str, managed_instance_name: str, parameters: _models.TdeCertificate, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[None]: """Creates a TDE certificate for a given server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param parameters: The requested TDE certificate to be created or updated. + :param parameters: The requested TDE certificate to be created or updated. Required. :type parameters: ~azure.mgmt.sql.models.TdeCertificate - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: + """ + + @overload + async def begin_create( + self, + resource_group_name: str, + managed_instance_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Creates a TDE certificate for a given server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param parameters: The requested TDE certificate to be created or updated. Required. + :type parameters: IO + :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: + """ + + @distributed_trace_async + async def begin_create( + self, + resource_group_name: str, + managed_instance_name: str, + parameters: Union[_models.TdeCertificate, IO], + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Creates a TDE certificate for a given server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param parameters: The requested TDE certificate to be created or updated. Is either a model + type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.TdeCertificate 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 @@ -126,20 +207,17 @@ async def begin_create( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + 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] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_initial( # type: ignore resource_group_name=resource_group_name, @@ -147,34 +225,30 @@ async def begin_create( # pylint: disable=inconsistent-return-statements parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_create.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/tdeCertificates"} # type: ignore + begin_create.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/tdeCertificates"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_vulnerability_assessments_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_vulnerability_assessments_operations.py index 510fa8482621e..6fe3e54d6dbbd 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_vulnerability_assessments_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instance_vulnerability_assessments_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_instance_vulnerability_assessments_operations import build_create_or_update_request, build_delete_request, build_get_request, build_list_by_instance_request -T = TypeVar('T') +from ...operations._managed_instance_vulnerability_assessments_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_instance_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedInstanceVulnerabilityAssessmentsOperations: """ .. warning:: @@ -43,7 +56,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -55,40 +67,35 @@ async def get( """Gets the managed instance's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param managed_instance_name: The name of the managed instance for which the vulnerability - assessment is defined. + assessment is defined. Required. :type managed_instance_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceVulnerabilityAssessment, or the result of cls(response) + :return: ManagedInstanceVulnerabilityAssessment or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceVulnerabilityAssessment - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceVulnerabilityAssessment] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceVulnerabilityAssessment] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -96,33 +103,33 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("ManagedInstanceVulnerabilityAssessment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, managed_instance_name: str, vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], parameters: _models.ManagedInstanceVulnerabilityAssessment, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.ManagedInstanceVulnerabilityAssessment: """Creates or updates the managed instance's vulnerability assessment. Learn more about setting @@ -130,36 +137,109 @@ async def create_or_update( https://docs.microsoft.com/azure/azure-sql/database/sql-database-vulnerability-assessment-storage. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param managed_instance_name: The name of the managed instance for which the vulnerability - assessment is defined. + assessment is defined. Required. :type managed_instance_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param parameters: The requested resource. + :param parameters: The requested resource. Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstanceVulnerabilityAssessment - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: ManagedInstanceVulnerabilityAssessment, or the result of cls(response) + :return: ManagedInstanceVulnerabilityAssessment or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceVulnerabilityAssessment - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.ManagedInstanceVulnerabilityAssessment: + """Creates or updates the managed instance's vulnerability assessment. Learn more about setting + SQL vulnerability assessment with managed identity - + https://docs.microsoft.com/azure/azure-sql/database/sql-database-vulnerability-assessment-storage. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance for which the vulnerability + assessment is defined. Required. + :type managed_instance_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param parameters: The requested resource. Required. + :type parameters: IO + :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: ManagedInstanceVulnerabilityAssessment or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedInstanceVulnerabilityAssessment + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + parameters: Union[_models.ManagedInstanceVulnerabilityAssessment, IO], + **kwargs: Any + ) -> _models.ManagedInstanceVulnerabilityAssessment: + """Creates or updates the managed instance's vulnerability assessment. Learn more about setting + SQL vulnerability assessment with managed identity - + https://docs.microsoft.com/azure/azure-sql/database/sql-database-vulnerability-assessment-storage. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance for which the vulnerability + assessment is defined. Required. + :type managed_instance_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param parameters: The requested resource. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceVulnerabilityAssessment 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 + :return: ManagedInstanceVulnerabilityAssessment or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedInstanceVulnerabilityAssessment + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceVulnerabilityAssessment] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceVulnerabilityAssessment] - _json = self._serialize.body(parameters, 'ManagedInstanceVulnerabilityAssessment') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceVulnerabilityAssessment") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -169,7 +249,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -177,10 +258,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -188,18 +268,17 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('ManagedInstanceVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("ManagedInstanceVulnerabilityAssessment", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedInstanceVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("ManagedInstanceVulnerabilityAssessment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -212,40 +291,35 @@ async def delete( # pylint: disable=inconsistent-return-statements """Removes the managed instance's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param managed_instance_name: The name of the managed instance for which the vulnerability - assessment is defined. + assessment is defined. Required. :type managed_instance_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -253,10 +327,9 @@ async def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -266,53 +339,45 @@ async def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstanceVulnerabilityAssessmentListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedInstanceVulnerabilityAssessment"]: """Gets the managed instance's vulnerability assessment policies. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param managed_instance_name: The name of the managed instance for which the vulnerability - assessments is defined. + assessments is defined. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceVulnerabilityAssessmentListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstanceVulnerabilityAssessment or the + result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceVulnerabilityAssessmentListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceVulnerabilityAssessment] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceVulnerabilityAssessmentListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceVulnerabilityAssessmentListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -320,16 +385,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -345,10 +401,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -358,8 +412,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instances_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instances_operations.py index a052943cacb9e..e5ffc00823293 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instances_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_instances_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,22 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_instances_operations import build_create_or_update_request_initial, build_delete_request_initial, build_failover_request_initial, build_get_request, build_list_by_instance_pool_request, build_list_by_managed_instance_request, build_list_by_resource_group_request, build_list_request, build_update_request_initial -T = TypeVar('T') +from ...operations._managed_instances_operations import ( + build_create_or_update_request, + build_delete_request, + build_failover_request, + build_get_request, + build_list_by_instance_pool_request, + build_list_by_managed_instance_request, + build_list_by_resource_group_request, + build_list_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedInstancesOperations: """ .. warning:: @@ -45,54 +63,43 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance_pool( - self, - resource_group_name: str, - instance_pool_name: str, - expand: Optional[str] = None, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstanceListResult]: + self, resource_group_name: str, instance_pool_name: str, expand: Optional[str] = None, **kwargs: Any + ) -> AsyncIterable["_models.ManagedInstance"]: """Gets a list of all managed instances in an instance pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param instance_pool_name: The instance pool name. + :param instance_pool_name: The instance pool name. Required. :type instance_pool_name: str :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedInstance or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstance] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_pool_request( resource_group_name=resource_group_name, instance_pool_name=instance_pool_name, subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.list_by_instance_pool.metadata['url'], + api_version=api_version, + template_url=self.list_by_instance_pool.metadata["url"], headers=_headers, params=_params, ) @@ -100,17 +107,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_pool_request( - resource_group_name=resource_group_name, - instance_pool_name=instance_pool_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - expand=expand, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -126,10 +123,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -139,50 +134,38 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_instance_pool.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}/managedInstances"} # type: ignore + list_by_instance_pool.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}/managedInstances"} # type: ignore @distributed_trace - def list( - self, - expand: Optional[str] = None, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstanceListResult]: + def list(self, expand: Optional[str] = None, **kwargs: Any) -> AsyncIterable["_models.ManagedInstance"]: """Gets a list of all managed instances in the subscription. :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedInstance or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstance] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_request( subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.list.metadata['url'], + api_version=api_version, + template_url=self.list.metadata["url"], headers=_headers, params=_params, ) @@ -190,15 +173,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_request( - subscription_id=self._config.subscription_id, - api_version=api_version, - expand=expand, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -214,10 +189,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -227,55 +200,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/managedInstances"} # type: ignore + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/managedInstances"} # type: ignore @distributed_trace def list_by_resource_group( - self, - resource_group_name: str, - expand: Optional[str] = None, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedInstanceListResult]: + self, resource_group_name: str, expand: Optional[str] = None, **kwargs: Any + ) -> AsyncIterable["_models.ManagedInstance"]: """Gets a list of managed instances in a resource group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstanceListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedInstance or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedInstance] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_request( resource_group_name=resource_group_name, subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.list_by_resource_group.metadata['url'], + api_version=api_version, + template_url=self.list_by_resource_group.metadata["url"], headers=_headers, params=_params, ) @@ -283,16 +245,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - expand=expand, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -308,10 +261,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -321,56 +272,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances"} # type: ignore + list_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - managed_instance_name: str, - expand: Optional[str] = None, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, expand: Optional[str] = None, **kwargs: Any ) -> _models.ManagedInstance: """Gets a managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstance, or the result of cls(response) + :return: ManagedInstance or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstance - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstance] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstance] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.get.metadata['url'], + api_version=api_version, + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -378,55 +317,58 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstance', pipeline_response) + deserialized = self._deserialize("ManagedInstance", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, - parameters: _models.ManagedInstance, + parameters: Union[_models.ManagedInstance, IO], **kwargs: Any ) -> Optional[_models.ManagedInstance]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedInstance]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstance]] - _json = self._serialize.body(parameters, 'ManagedInstance') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstance") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -434,10 +376,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -446,39 +387,40 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedInstance', pipeline_response) + deserialized = self._deserialize("ManagedInstance", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedInstance', pipeline_response) + deserialized = self._deserialize("ManagedInstance", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, parameters: _models.ManagedInstance, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ManagedInstance]: """Creates or updates a managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param parameters: The requested managed instance resource state. + :param parameters: The requested managed instance resource state. Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstance - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -490,20 +432,88 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either ManagedInstance or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstance] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstance]: + """Creates or updates a managed instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param parameters: The requested managed instance resource state. Required. + :type parameters: IO + :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 ManagedInstance or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstance] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + parameters: Union[_models.ManagedInstance, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstance]: + """Creates or updates a managed instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param parameters: The requested managed instance resource state. Is either a model type or a + IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstance 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. + :return: An instance of AsyncLROPoller that returns either ManagedInstance or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstance] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstance] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstance] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -511,64 +521,54 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedInstance', pipeline_response) + deserialized = self._deserialize("ManagedInstance", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -576,10 +576,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -589,26 +588,19 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes a managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -619,85 +611,83 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore async def _update_initial( self, resource_group_name: str, managed_instance_name: str, - parameters: _models.ManagedInstanceUpdate, + parameters: Union[_models.ManagedInstanceUpdate, IO], **kwargs: Any ) -> Optional[_models.ManagedInstance]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedInstance]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstance]] - _json = self._serialize.body(parameters, 'ManagedInstanceUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -705,10 +695,9 @@ async def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -717,36 +706,37 @@ async def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedInstance', pipeline_response) + deserialized = self._deserialize("ManagedInstance", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_update( self, resource_group_name: str, managed_instance_name: str, parameters: _models.ManagedInstanceUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ManagedInstance]: """Updates a managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param parameters: The requested managed instance resource state. + :param parameters: The requested managed instance resource state. Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstanceUpdate - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -758,20 +748,88 @@ async def begin_update( :return: An instance of AsyncLROPoller that returns either ManagedInstance or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstance] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstance]: + """Updates a managed instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param parameters: The requested managed instance resource state. Required. + :type parameters: IO + :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 ManagedInstance or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstance] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + parameters: Union[_models.ManagedInstanceUpdate, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedInstance]: + """Updates a managed instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param parameters: The requested managed instance resource state. Is either a model type or a + IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceUpdate 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. + :return: An instance of AsyncLROPoller that returns either ManagedInstance or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedInstance] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstance] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstance] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -779,39 +837,35 @@ async def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedInstance', pipeline_response) + deserialized = self._deserialize("ManagedInstance", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore @distributed_trace def list_by_managed_instance( @@ -826,15 +880,16 @@ def list_by_managed_instance( aggregation_function: Optional[Union[str, "_models.AggregationFunctionType"]] = None, observation_metric: Optional[Union[str, "_models.MetricType"]] = None, **kwargs: Any - ) -> AsyncIterable[_models.TopQueriesListResult]: + ) -> AsyncIterable["_models.TopQueries"]: """Get top resource consuming queries of a managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param number_of_queries: How many 'top queries' to return. Default is 5. + :param number_of_queries: How many 'top queries' to return. Default is 5. Default value is + None. :type number_of_queries: int :param databases: Comma separated list of databases to be included into search. All DB's are included if this parameter is not specified. Default value is None. @@ -844,39 +899,35 @@ def list_by_managed_instance( :param end_time: End time for observed period. Default value is None. :type end_time: str :param interval: The time step to be used to summarize the metric values. Default value is - PT1H. + PT1H. Known values are: "PT1H" and "P1D". Default value is None. :type interval: str or ~azure.mgmt.sql.models.QueryTimeGrainType - :param aggregation_function: Aggregation function to be used, default value is 'sum'. + :param aggregation_function: Aggregation function to be used, default value is 'sum'. Known + values are: "avg", "min", "max", "stdev", and "sum". Default value is None. :type aggregation_function: str or ~azure.mgmt.sql.models.AggregationFunctionType - :param observation_metric: Metric to be used for ranking top queries. Default is 'cpu'. + :param observation_metric: Metric to be used for ranking top queries. Default is 'cpu'. Known + values are: "cpu", "io", "logIo", "duration", and "dtu". Default value is None. :type observation_metric: str or ~azure.mgmt.sql.models.MetricType - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either TopQueriesListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.TopQueriesListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either TopQueries or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.TopQueries] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.TopQueriesListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.TopQueriesListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_managed_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, - api_version=api_version, number_of_queries=number_of_queries, databases=databases, start_time=start_time, @@ -884,7 +935,8 @@ def prepare_request(next_link=None): interval=interval, aggregation_function=aggregation_function, observation_metric=observation_metric, - template_url=self.list_by_managed_instance.metadata['url'], + api_version=api_version, + template_url=self.list_by_managed_instance.metadata["url"], headers=_headers, params=_params, ) @@ -892,23 +944,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_managed_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - number_of_queries=number_of_queries, - databases=databases, - start_time=start_time, - end_time=end_time, - interval=interval, - aggregation_function=aggregation_function, - observation_metric=observation_metric, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -924,10 +960,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -937,11 +971,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_managed_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/topqueries"} # type: ignore + list_by_managed_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/topqueries"} # type: ignore async def _failover_initial( # pylint: disable=inconsistent-return-statements self, @@ -950,25 +982,22 @@ async def _failover_initial( # pylint: disable=inconsistent-return-statements replica_type: Optional[Union[str, "_models.ReplicaType"]] = None, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_failover_request_initial( + request = build_failover_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, - api_version=api_version, replica_type=replica_type, - template_url=self._failover_initial.metadata['url'], + api_version=api_version, + template_url=self._failover_initial.metadata["url"], headers=_headers, params=_params, ) @@ -976,10 +1005,9 @@ async def _failover_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -989,11 +1017,10 @@ async def _failover_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _failover_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/failover"} # type: ignore - + _failover_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/failover"} # type: ignore @distributed_trace_async - async def begin_failover( # pylint: disable=inconsistent-return-statements + async def begin_failover( self, resource_group_name: str, managed_instance_name: str, @@ -1003,15 +1030,13 @@ async def begin_failover( # pylint: disable=inconsistent-return-statements """Failovers a managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance to failover. + :param managed_instance_name: The name of the managed instance to failover. Required. :type managed_instance_name: str - :param replica_type: The type of replica to be failed over. Default value is None. + :param replica_type: The type of replica to be failed over. Known values are: "Primary" and + "ReadableSecondary". Default value is None. :type replica_type: str or ~azure.mgmt.sql.models.ReplicaType - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1022,53 +1047,46 @@ async def begin_failover( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._failover_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, replica_type=replica_type, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_failover.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/failover"} # type: ignore + begin_failover.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/failover"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_restorable_dropped_database_backup_short_term_retention_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_restorable_dropped_database_backup_short_term_retention_policies_operations.py index 0a4ad813a0560..d757dfea1e89b 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_restorable_dropped_database_backup_short_term_retention_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_restorable_dropped_database_backup_short_term_retention_policies_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_restorable_dropped_database_backup_short_term_retention_policies_operations import build_create_or_update_request_initial, build_get_request, build_list_by_restorable_dropped_database_request, build_update_request_initial -T = TypeVar('T') +from ...operations._managed_restorable_dropped_database_backup_short_term_retention_policies_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_restorable_dropped_database_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations: """ .. warning:: @@ -45,7 +58,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -58,34 +70,28 @@ async def get( """Gets a dropped database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param restorable_dropped_database_id: + :param restorable_dropped_database_id: Required. :type restorable_dropped_database_id: str - :param policy_name: The policy name. + :param policy_name: The policy name. "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedBackupShortTermRetentionPolicy, or the result of cls(response) + :return: ManagedBackupShortTermRetentionPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -93,7 +99,7 @@ async def get( policy_name=policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -101,25 +107,23 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore async def _create_or_update_initial( self, @@ -127,24 +131,28 @@ async def _create_or_update_initial( managed_instance_name: str, restorable_dropped_database_id: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], - parameters: _models.ManagedBackupShortTermRetentionPolicy, + parameters: Union[_models.ManagedBackupShortTermRetentionPolicy, IO], **kwargs: Any ) -> Optional[_models.ManagedBackupShortTermRetentionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedBackupShortTermRetentionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedBackupShortTermRetentionPolicy]] - _json = self._serialize.body(parameters, 'ManagedBackupShortTermRetentionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedBackupShortTermRetentionPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, restorable_dropped_database_id=restorable_dropped_database_id, @@ -153,7 +161,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -161,10 +170,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -173,17 +181,16 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, @@ -191,24 +198,26 @@ async def begin_create_or_update( restorable_dropped_database_id: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], parameters: _models.ManagedBackupShortTermRetentionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ManagedBackupShortTermRetentionPolicy]: """Sets a database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param restorable_dropped_database_id: + :param restorable_dropped_database_id: Required. :type restorable_dropped_database_id: str - :param policy_name: The policy name. Should always be "default". + :param policy_name: The policy name. Should always be "default". "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName - :param parameters: The short term retention policy info. + :param parameters: The short term retention policy info. Required. :type parameters: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -221,20 +230,102 @@ async def begin_create_or_update( ManagedBackupShortTermRetentionPolicy or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + restorable_dropped_database_id: str, + policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedBackupShortTermRetentionPolicy]: + """Sets a database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param restorable_dropped_database_id: Required. + :type restorable_dropped_database_id: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Required. + :type parameters: IO + :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 + ManagedBackupShortTermRetentionPolicy or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + restorable_dropped_database_id: str, + policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], + parameters: Union[_models.ManagedBackupShortTermRetentionPolicy, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedBackupShortTermRetentionPolicy]: + """Sets a database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param restorable_dropped_database_id: Required. + :type restorable_dropped_database_id: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy 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. + :return: An instance of AsyncLROPoller that returns either + ManagedBackupShortTermRetentionPolicy or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -244,39 +335,35 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore async def _update_initial( self, @@ -284,24 +371,28 @@ async def _update_initial( managed_instance_name: str, restorable_dropped_database_id: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], - parameters: _models.ManagedBackupShortTermRetentionPolicy, + parameters: Union[_models.ManagedBackupShortTermRetentionPolicy, IO], **kwargs: Any ) -> Optional[_models.ManagedBackupShortTermRetentionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedBackupShortTermRetentionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedBackupShortTermRetentionPolicy]] - _json = self._serialize.body(parameters, 'ManagedBackupShortTermRetentionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedBackupShortTermRetentionPolicy") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, restorable_dropped_database_id=restorable_dropped_database_id, @@ -310,7 +401,8 @@ async def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -318,10 +410,9 @@ async def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -330,17 +421,16 @@ async def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - @distributed_trace_async + @overload async def begin_update( self, resource_group_name: str, @@ -348,24 +438,69 @@ async def begin_update( restorable_dropped_database_id: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], parameters: _models.ManagedBackupShortTermRetentionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ManagedBackupShortTermRetentionPolicy]: """Sets a database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param restorable_dropped_database_id: + :param restorable_dropped_database_id: Required. :type restorable_dropped_database_id: str - :param policy_name: The policy name. Should always be "default". + :param policy_name: The policy name. Should always be "default". "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName - :param parameters: The short term retention policy info. + :param parameters: The short term retention policy info. Required. :type parameters: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 + ManagedBackupShortTermRetentionPolicy or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + restorable_dropped_database_id: str, + policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedBackupShortTermRetentionPolicy]: + """Sets a database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param restorable_dropped_database_id: Required. + :type restorable_dropped_database_id: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Required. + :type parameters: IO + :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 @@ -378,20 +513,59 @@ async def begin_update( ManagedBackupShortTermRetentionPolicy or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + restorable_dropped_database_id: str, + policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], + parameters: Union[_models.ManagedBackupShortTermRetentionPolicy, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedBackupShortTermRetentionPolicy]: + """Sets a database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param restorable_dropped_database_id: Required. + :type restorable_dropped_database_id: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy 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. + :return: An instance of AsyncLROPoller that returns either + ManagedBackupShortTermRetentionPolicy or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -401,87 +575,75 @@ async def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore @distributed_trace def list_by_restorable_dropped_database( - self, - resource_group_name: str, - managed_instance_name: str, - restorable_dropped_database_id: str, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedBackupShortTermRetentionPolicyListResult]: + self, resource_group_name: str, managed_instance_name: str, restorable_dropped_database_id: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedBackupShortTermRetentionPolicy"]: """Gets a dropped database's short term retention policy list. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param restorable_dropped_database_id: + :param restorable_dropped_database_id: Required. :type restorable_dropped_database_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedBackupShortTermRetentionPolicyListResult or - the result of cls(response) + :return: An iterator like instance of either ManagedBackupShortTermRetentionPolicy or the + result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_restorable_dropped_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, restorable_dropped_database_id=restorable_dropped_database_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_restorable_dropped_database.metadata['url'], + template_url=self.list_by_restorable_dropped_database.metadata["url"], headers=_headers, params=_params, ) @@ -489,17 +651,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_restorable_dropped_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - restorable_dropped_database_id=restorable_dropped_database_id, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -515,10 +667,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -528,8 +678,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_restorable_dropped_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies"} # type: ignore + list_by_restorable_dropped_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_server_dns_aliases_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_server_dns_aliases_operations.py index 1dff22e681777..ab7e189a7d5e0 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_server_dns_aliases_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_server_dns_aliases_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,18 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_server_dns_aliases_operations import build_acquire_request_initial, build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_managed_instance_request -T = TypeVar('T') +from ...operations._managed_server_dns_aliases_operations import ( + build_acquire_request, + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_managed_instance_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedServerDnsAliasesOperations: """ .. warning:: @@ -45,50 +59,41 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_managed_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedServerDnsAliasListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedServerDnsAlias"]: """Gets a list of managed server DNS aliases for a managed server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedServerDnsAliasListResult or the result of + :return: An iterator like instance of either ManagedServerDnsAlias or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedServerDnsAliasListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedServerDnsAlias] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedServerDnsAliasListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedServerDnsAliasListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_managed_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_managed_instance.metadata['url'], + template_url=self.list_by_managed_instance.metadata["url"], headers=_headers, params=_params, ) @@ -96,16 +101,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_managed_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -121,10 +117,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -134,56 +128,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_managed_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases"} # type: ignore + list_by_managed_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - managed_instance_name: str, - dns_alias_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, dns_alias_name: str, **kwargs: Any ) -> _models.ManagedServerDnsAlias: """Gets a server DNS alias. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param dns_alias_name: + :param dns_alias_name: Required. :type dns_alias_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedServerDnsAlias, or the result of cls(response) + :return: ManagedServerDnsAlias or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedServerDnsAlias - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedServerDnsAlias] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedServerDnsAlias] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, dns_alias_name=dns_alias_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -191,49 +173,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ManagedServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, dns_alias_name: str, - parameters: _models.ManagedServerDnsAliasCreation, + parameters: Union[_models.ManagedServerDnsAliasCreation, IO], **kwargs: Any ) -> Optional[_models.ManagedServerDnsAlias]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedServerDnsAlias]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedServerDnsAlias]] - _json = self._serialize.body(parameters, 'ManagedServerDnsAliasCreation') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedServerDnsAliasCreation") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, dns_alias_name=dns_alias_name, @@ -241,7 +225,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -249,10 +234,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -261,42 +245,43 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ManagedServerDnsAlias", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ManagedServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, dns_alias_name: str, parameters: _models.ManagedServerDnsAliasCreation, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ManagedServerDnsAlias]: """Creates a managed server DNS alias. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param dns_alias_name: + :param dns_alias_name: Required. :type dns_alias_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.ManagedServerDnsAliasCreation - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -308,20 +293,93 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either ManagedServerDnsAlias or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedServerDnsAlias] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + dns_alias_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedServerDnsAlias]: + """Creates a managed server DNS alias. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param dns_alias_name: Required. + :type dns_alias_name: str + :param parameters: Required. + :type parameters: IO + :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 ManagedServerDnsAlias or the result + of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedServerDnsAlias] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + dns_alias_name: str, + parameters: Union[_models.ManagedServerDnsAliasCreation, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedServerDnsAlias]: + """Creates a managed server DNS alias. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param dns_alias_name: Required. + :type dns_alias_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedServerDnsAliasCreation 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. + :return: An instance of AsyncLROPoller that returns either ManagedServerDnsAlias or the result + of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedServerDnsAlias] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedServerDnsAlias] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedServerDnsAlias] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -330,66 +388,55 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ManagedServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - dns_alias_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, dns_alias_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, dns_alias_name=dns_alias_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -397,10 +444,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -410,29 +456,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - dns_alias_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, managed_instance_name: str, dns_alias_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes the managed server DNS alias with the given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param dns_alias_name: + :param dns_alias_name: Required. :type dns_alias_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -443,80 +481,77 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, dns_alias_name=dns_alias_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore async def _acquire_initial( self, resource_group_name: str, managed_instance_name: str, dns_alias_name: str, - parameters: _models.ManagedServerDnsAliasAcquisition, + parameters: Union[_models.ManagedServerDnsAliasAcquisition, IO], **kwargs: Any ) -> Optional[_models.ManagedServerDnsAlias]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedServerDnsAlias]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedServerDnsAlias]] - _json = self._serialize.body(parameters, 'ManagedServerDnsAliasAcquisition') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedServerDnsAliasAcquisition") - request = build_acquire_request_initial( + request = build_acquire_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, dns_alias_name=dns_alias_name, @@ -524,7 +559,8 @@ async def _acquire_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._acquire_initial.metadata['url'], + content=_content, + template_url=self._acquire_initial.metadata["url"], headers=_headers, params=_params, ) @@ -532,10 +568,9 @@ async def _acquire_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -544,39 +579,116 @@ async def _acquire_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ManagedServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _acquire_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}/acquire"} # type: ignore - + _acquire_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}/acquire"} # type: ignore - @distributed_trace_async + @overload async def begin_acquire( self, resource_group_name: str, managed_instance_name: str, dns_alias_name: str, parameters: _models.ManagedServerDnsAliasAcquisition, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ManagedServerDnsAlias]: """Acquires managed server DNS alias from another managed server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param dns_alias_name: + :param dns_alias_name: Required. :type dns_alias_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.ManagedServerDnsAliasAcquisition - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ManagedServerDnsAlias or the result + of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedServerDnsAlias] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_acquire( + self, + resource_group_name: str, + managed_instance_name: str, + dns_alias_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedServerDnsAlias]: + """Acquires managed server DNS alias from another managed server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param dns_alias_name: Required. + :type dns_alias_name: str + :param parameters: Required. + :type parameters: IO + :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 ManagedServerDnsAlias or the result + of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedServerDnsAlias] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_acquire( + self, + resource_group_name: str, + managed_instance_name: str, + dns_alias_name: str, + parameters: Union[_models.ManagedServerDnsAliasAcquisition, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedServerDnsAlias]: + """Acquires managed server DNS alias from another managed server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param dns_alias_name: Required. + :type dns_alias_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedServerDnsAliasAcquisition 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 @@ -588,20 +700,17 @@ async def begin_acquire( :return: An instance of AsyncLROPoller that returns either ManagedServerDnsAlias or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedServerDnsAlias] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedServerDnsAlias] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedServerDnsAlias] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._acquire_initial( # type: ignore resource_group_name=resource_group_name, @@ -610,36 +719,32 @@ async def begin_acquire( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ManagedServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_acquire.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}/acquire"} # type: ignore + begin_acquire.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}/acquire"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_server_security_alert_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_server_security_alert_policies_operations.py index e0c0767a6a725..f72d21d1d986b 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_server_security_alert_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_managed_server_security_alert_policies_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._managed_server_security_alert_policies_operations import build_create_or_update_request_initial, build_get_request, build_list_by_instance_request -T = TypeVar('T') +from ...operations._managed_server_security_alert_policies_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_instance_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ManagedServerSecurityAlertPoliciesOperations: """ .. warning:: @@ -45,7 +57,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -57,39 +68,33 @@ async def get( """Get a managed server's threat detection policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param security_alert_policy_name: The name of the security alert policy. + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedServerSecurityAlertPolicy, or the result of cls(response) + :return: ManagedServerSecurityAlertPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedServerSecurityAlertPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedServerSecurityAlertPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedServerSecurityAlertPolicy] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, security_alert_policy_name=security_alert_policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,49 +102,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedServerSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ManagedServerSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], - parameters: _models.ManagedServerSecurityAlertPolicy, + parameters: Union[_models.ManagedServerSecurityAlertPolicy, IO], **kwargs: Any ) -> Optional[_models.ManagedServerSecurityAlertPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedServerSecurityAlertPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedServerSecurityAlertPolicy]] - _json = self._serialize.body(parameters, 'ManagedServerSecurityAlertPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedServerSecurityAlertPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, security_alert_policy_name=security_alert_policy_name, @@ -147,7 +154,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -155,10 +163,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -167,39 +174,80 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedServerSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ManagedServerSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], parameters: _models.ManagedServerSecurityAlertPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ManagedServerSecurityAlertPolicy]: """Creates or updates a threat detection policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param security_alert_policy_name: The name of the security alert policy. + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName - :param parameters: The managed server security alert policy. + :param parameters: The managed server security alert policy. Required. :type parameters: ~azure.mgmt.sql.models.ManagedServerSecurityAlertPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ManagedServerSecurityAlertPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedServerSecurityAlertPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedServerSecurityAlertPolicy]: + """Creates or updates a threat detection policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. + :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName + :param parameters: The managed server security alert policy. Required. + :type parameters: IO + :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 @@ -212,20 +260,56 @@ async def begin_create_or_update( the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedServerSecurityAlertPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], + parameters: Union[_models.ManagedServerSecurityAlertPolicy, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ManagedServerSecurityAlertPolicy]: + """Creates or updates a threat detection policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. + :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName + :param parameters: The managed server security alert policy. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedServerSecurityAlertPolicy 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. + :return: An instance of AsyncLROPoller that returns either ManagedServerSecurityAlertPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ManagedServerSecurityAlertPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedServerSecurityAlertPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedServerSecurityAlertPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -234,83 +318,72 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedServerSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ManagedServerSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ManagedServerSecurityAlertPolicyListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ManagedServerSecurityAlertPolicy"]: """Get the managed server's threat detection policies. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedServerSecurityAlertPolicyListResult or the - result of cls(response) + :return: An iterator like instance of either ManagedServerSecurityAlertPolicy or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedServerSecurityAlertPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ManagedServerSecurityAlertPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedServerSecurityAlertPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedServerSecurityAlertPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -318,16 +391,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -343,10 +407,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -356,8 +418,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_operations.py index 7f10bd462e008..0ba94172e79b8 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,9 +26,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._operations import build_list_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class Operations: """ .. warning:: @@ -42,38 +50,30 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace - def list( - self, - **kwargs: Any - ) -> AsyncIterable[_models.OperationListResult]: + def list(self, **kwargs: Any) -> AsyncIterable["_models.Operation"]: """Lists all of the available SQL Rest API operations. - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either OperationListResult or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.OperationListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Operation or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.Operation] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.OperationListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.OperationListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_request( api_version=api_version, - template_url=self.list.metadata['url'], + template_url=self.list.metadata["url"], headers=_headers, params=_params, ) @@ -81,13 +81,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_request( - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -103,10 +97,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -116,8 +108,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list.metadata = {'url': "/providers/Microsoft.Sql/operations"} # type: ignore + list.metadata = {"url": "/providers/Microsoft.Sql/operations"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_outbound_firewall_rules_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_outbound_firewall_rules_operations.py index ac52cd0fe9b6f..c11312e8768b8 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_outbound_firewall_rules_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_outbound_firewall_rules_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._outbound_firewall_rules_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_server_request -T = TypeVar('T') +from ...operations._outbound_firewall_rules_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_server_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class OutboundFirewallRulesOperations: """ .. warning:: @@ -45,51 +58,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - outbound_rule_fqdn: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, outbound_rule_fqdn: str, **kwargs: Any ) -> _models.OutboundFirewallRule: """Gets an outbound firewall rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param outbound_rule_fqdn: + :param outbound_rule_fqdn: Required. :type outbound_rule_fqdn: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: OutboundFirewallRule, or the result of cls(response) + :return: OutboundFirewallRule or the result of cls(response) :rtype: ~azure.mgmt.sql.models.OutboundFirewallRule - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.OutboundFirewallRule] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.OutboundFirewallRule] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, outbound_rule_fqdn=outbound_rule_fqdn, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,49 +99,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('OutboundFirewallRule', pipeline_response) + deserialized = self._deserialize("OutboundFirewallRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, outbound_rule_fqdn: str, - parameters: _models.OutboundFirewallRule, + parameters: Union[_models.OutboundFirewallRule, IO], **kwargs: Any ) -> Optional[_models.OutboundFirewallRule]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.OutboundFirewallRule]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.OutboundFirewallRule]] - _json = self._serialize.body(parameters, 'OutboundFirewallRule') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "OutboundFirewallRule") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, outbound_rule_fqdn=outbound_rule_fqdn, @@ -147,7 +151,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -155,10 +160,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -167,42 +171,43 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('OutboundFirewallRule', pipeline_response) + deserialized = self._deserialize("OutboundFirewallRule", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('OutboundFirewallRule', pipeline_response) + deserialized = self._deserialize("OutboundFirewallRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, outbound_rule_fqdn: str, parameters: _models.OutboundFirewallRule, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.OutboundFirewallRule]: """Create a outbound firewall rule with a given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param outbound_rule_fqdn: + :param outbound_rule_fqdn: Required. :type outbound_rule_fqdn: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.OutboundFirewallRule - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -214,20 +219,93 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either OutboundFirewallRule or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.OutboundFirewallRule] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + outbound_rule_fqdn: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.OutboundFirewallRule]: + """Create a outbound firewall rule with a given name. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param outbound_rule_fqdn: Required. + :type outbound_rule_fqdn: str + :param parameters: Required. + :type parameters: IO + :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 OutboundFirewallRule or the result + of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.OutboundFirewallRule] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + outbound_rule_fqdn: str, + parameters: Union[_models.OutboundFirewallRule, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.OutboundFirewallRule]: + """Create a outbound firewall rule with a given name. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param outbound_rule_fqdn: Required. + :type outbound_rule_fqdn: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.OutboundFirewallRule 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. + :return: An instance of AsyncLROPoller that returns either OutboundFirewallRule or the result + of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.OutboundFirewallRule] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.OutboundFirewallRule] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.OutboundFirewallRule] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -236,66 +314,55 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('OutboundFirewallRule', pipeline_response) + deserialized = self._deserialize("OutboundFirewallRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - outbound_rule_fqdn: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, outbound_rule_fqdn: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, outbound_rule_fqdn=outbound_rule_fqdn, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -303,10 +370,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -316,29 +382,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - outbound_rule_fqdn: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, server_name: str, outbound_rule_fqdn: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes a outbound firewall rule with a given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param outbound_rule_fqdn: + :param outbound_rule_fqdn: Required. :type outbound_rule_fqdn: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -349,100 +407,85 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, outbound_rule_fqdn=outbound_rule_fqdn, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.OutboundFirewallRuleListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.OutboundFirewallRule"]: """Gets all outbound firewall rules on a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either OutboundFirewallRuleListResult or the result of + :return: An iterator like instance of either OutboundFirewallRule or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.OutboundFirewallRuleListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.OutboundFirewallRule] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.OutboundFirewallRuleListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.OutboundFirewallRuleListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -450,16 +493,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -475,10 +509,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -488,8 +520,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_patch.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_patch.py index 0ad201a8c586e..f7dd32510333d 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_patch.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_patch.py @@ -10,6 +10,7 @@ __all__: List[str] = [] # Add all objects you want publicly available to users at this package level + def patch_sdk(): """Do not remove from this file. diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_private_endpoint_connections_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_private_endpoint_connections_operations.py index 504a7b5369eda..53a2ebbab3ca5 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_private_endpoint_connections_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_private_endpoint_connections_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._private_endpoint_connections_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_server_request -T = TypeVar('T') +from ...operations._private_endpoint_connections_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_server_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class PrivateEndpointConnectionsOperations: """ .. warning:: @@ -45,51 +58,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - private_endpoint_connection_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, private_endpoint_connection_name: str, **kwargs: Any ) -> _models.PrivateEndpointConnection: """Gets a private endpoint connection. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param private_endpoint_connection_name: The name of the private endpoint connection. + :param private_endpoint_connection_name: The name of the private endpoint connection. Required. :type private_endpoint_connection_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: PrivateEndpointConnection, or the result of cls(response) + :return: PrivateEndpointConnection or the result of cls(response) :rtype: ~azure.mgmt.sql.models.PrivateEndpointConnection - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.PrivateEndpointConnection] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.PrivateEndpointConnection] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, private_endpoint_connection_name=private_endpoint_connection_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,49 +99,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('PrivateEndpointConnection', pipeline_response) + deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, private_endpoint_connection_name: str, - parameters: _models.PrivateEndpointConnection, + parameters: Union[_models.PrivateEndpointConnection, IO], **kwargs: Any ) -> Optional[_models.PrivateEndpointConnection]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.PrivateEndpointConnection]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.PrivateEndpointConnection]] - _json = self._serialize.body(parameters, 'PrivateEndpointConnection') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "PrivateEndpointConnection") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, private_endpoint_connection_name=private_endpoint_connection_name, @@ -147,7 +151,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -155,10 +160,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -167,39 +171,40 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('PrivateEndpointConnection', pipeline_response) + deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, private_endpoint_connection_name: str, parameters: _models.PrivateEndpointConnection, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.PrivateEndpointConnection]: """Approve or reject a private endpoint connection with a given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param private_endpoint_connection_name: + :param private_endpoint_connection_name: Required. :type private_endpoint_connection_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.PrivateEndpointConnection - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -211,20 +216,93 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either PrivateEndpointConnection or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.PrivateEndpointConnection] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + private_endpoint_connection_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.PrivateEndpointConnection]: + """Approve or reject a private endpoint connection with a given name. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param private_endpoint_connection_name: Required. + :type private_endpoint_connection_name: str + :param parameters: Required. + :type parameters: IO + :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 PrivateEndpointConnection or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.PrivateEndpointConnection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + private_endpoint_connection_name: str, + parameters: Union[_models.PrivateEndpointConnection, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.PrivateEndpointConnection]: + """Approve or reject a private endpoint connection with a given name. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param private_endpoint_connection_name: Required. + :type private_endpoint_connection_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.PrivateEndpointConnection 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. + :return: An instance of AsyncLROPoller that returns either PrivateEndpointConnection or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.PrivateEndpointConnection] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.PrivateEndpointConnection] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.PrivateEndpointConnection] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -233,66 +311,55 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('PrivateEndpointConnection', pipeline_response) + deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - private_endpoint_connection_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, private_endpoint_connection_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, private_endpoint_connection_name=private_endpoint_connection_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -300,10 +367,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -313,29 +379,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - private_endpoint_connection_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, server_name: str, private_endpoint_connection_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes a private endpoint connection with a given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param private_endpoint_connection_name: + :param private_endpoint_connection_name: Required. :type private_endpoint_connection_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -346,100 +404,86 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, private_endpoint_connection_name=private_endpoint_connection_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.PrivateEndpointConnectionListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.PrivateEndpointConnection"]: """Gets all private endpoint connections on a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PrivateEndpointConnectionListResult or the result - of cls(response) + :return: An iterator like instance of either PrivateEndpointConnection or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.PrivateEndpointConnectionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.PrivateEndpointConnection] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.PrivateEndpointConnectionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.PrivateEndpointConnectionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -447,16 +491,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -472,10 +507,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -485,8 +518,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_private_link_resources_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_private_link_resources_operations.py index 88562f1632201..8b468e3a363c6 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_private_link_resources_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_private_link_resources_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._private_link_resources_operations import build_get_request, build_list_by_server_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class PrivateLinkResourcesOperations: """ .. warning:: @@ -43,50 +51,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.PrivateLinkResourceListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.PrivateLinkResource"]: """Gets the private link resources for SQL server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PrivateLinkResourceListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.PrivateLinkResourceListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either PrivateLinkResource or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.PrivateLinkResource] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.PrivateLinkResourceListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.PrivateLinkResourceListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -94,16 +92,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -119,10 +108,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -132,56 +119,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateLinkResources"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateLinkResources"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, group_name: str, **kwargs: Any ) -> _models.PrivateLinkResource: """Gets a private link resource for SQL server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param group_name: The name of the private link resource. + :param group_name: The name of the private link resource. Required. :type group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: PrivateLinkResource, or the result of cls(response) + :return: PrivateLinkResource or the result of cls(response) :rtype: ~azure.mgmt.sql.models.PrivateLinkResource - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.PrivateLinkResource] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.PrivateLinkResource] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, group_name=group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -189,22 +164,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('PrivateLinkResource', pipeline_response) + deserialized = self._deserialize("PrivateLinkResource", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateLinkResources/{groupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateLinkResources/{groupName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_recommended_sensitivity_labels_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_recommended_sensitivity_labels_operations.py index a0a0fec0a6235..9356e5920f0da 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_recommended_sensitivity_labels_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_recommended_sensitivity_labels_operations.py @@ -6,9 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -19,9 +25,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._recommended_sensitivity_labels_operations import build_update_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class RecommendedSensitivityLabelsOperations: """ .. warning:: @@ -41,48 +49,113 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace_async + @overload async def update( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.RecommendedSensitivityLabelUpdateList, + *, + content_type: str = "application/json", **kwargs: Any ) -> None: """Update recommended sensitivity labels states of a given database using an operations batch. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.RecommendedSensitivityLabelUpdateList - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> None: + """Update recommended sensitivity labels states of a given database using an operations batch. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Required. + :type parameters: IO + :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: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace_async + async def update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.RecommendedSensitivityLabelUpdateList, IO], + **kwargs: Any + ) -> None: + """Update recommended sensitivity labels states of a given database using an operations batch. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.RecommendedSensitivityLabelUpdateList 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 + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'RecommendedSensitivityLabelUpdateList') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "RecommendedSensitivityLabelUpdateList") request = build_update_request( resource_group_name=resource_group_name, @@ -92,7 +165,8 @@ async def update( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -100,10 +174,9 @@ async def update( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -113,5 +186,4 @@ async def update( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/recommendedSensitivityLabels"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/recommendedSensitivityLabels"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_recoverable_databases_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_recoverable_databases_operations.py index 33ca52143575a..49652c01e07b2 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_recoverable_databases_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_recoverable_databases_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._recoverable_databases_operations import build_get_request, build_list_by_server_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class RecoverableDatabasesOperations: """ .. warning:: @@ -43,51 +51,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> _models.RecoverableDatabase: """Gets a recoverable database, which is a resource representing a database's geo backup. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: RecoverableDatabase, or the result of cls(response) + :return: RecoverableDatabase or the result of cls(response) :rtype: ~azure.mgmt.sql.models.RecoverableDatabase - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RecoverableDatabase] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RecoverableDatabase] - request = build_get_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -95,69 +92,58 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('RecoverableDatabase', pipeline_response) + deserialized = self._deserialize("RecoverableDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/recoverableDatabases/{databaseName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/recoverableDatabases/{databaseName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.RecoverableDatabaseListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.RecoverableDatabase"]: """Gets a list of recoverable databases. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either RecoverableDatabaseListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.RecoverableDatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either RecoverableDatabase or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.RecoverableDatabase] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RecoverableDatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RecoverableDatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -165,16 +151,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -190,10 +167,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -203,8 +178,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/recoverableDatabases"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/recoverableDatabases"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_recoverable_managed_databases_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_recoverable_managed_databases_operations.py index 2cfb6f450278d..78e269462521c 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_recoverable_managed_databases_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_recoverable_managed_databases_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._recoverable_managed_databases_operations import build_get_request, build_list_by_instance_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class RecoverableManagedDatabasesOperations: """ .. warning:: @@ -43,50 +51,42 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.RecoverableManagedDatabaseListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.RecoverableManagedDatabase"]: """Gets a list of recoverable managed databases. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either RecoverableManagedDatabaseListResult or the result - of cls(response) + :return: An iterator like instance of either RecoverableManagedDatabase or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.RecoverableManagedDatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.RecoverableManagedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RecoverableManagedDatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RecoverableManagedDatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -94,16 +94,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -119,10 +110,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -132,56 +121,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/recoverableDatabases"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/recoverableDatabases"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - managed_instance_name: str, - recoverable_database_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, recoverable_database_name: str, **kwargs: Any ) -> _models.RecoverableManagedDatabase: """Gets a recoverable managed database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param recoverable_database_name: + :param recoverable_database_name: Required. :type recoverable_database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: RecoverableManagedDatabase, or the result of cls(response) + :return: RecoverableManagedDatabase or the result of cls(response) :rtype: ~azure.mgmt.sql.models.RecoverableManagedDatabase - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RecoverableManagedDatabase] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RecoverableManagedDatabase] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, recoverable_database_name=recoverable_database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -189,22 +166,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('RecoverableManagedDatabase', pipeline_response) + deserialized = self._deserialize("RecoverableManagedDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/recoverableDatabases/{recoverableDatabaseName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/recoverableDatabases/{recoverableDatabaseName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_replication_links_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_replication_links_operations.py index 05bee6bb57d6a..b7db3d82413d0 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_replication_links_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_replication_links_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,19 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._replication_links_operations import build_delete_request, build_failover_allow_data_loss_request_initial, build_failover_request_initial, build_get_request, build_list_by_database_request, build_list_by_server_request -T = TypeVar('T') +from ...operations._replication_links_operations import ( + build_delete_request, + build_failover_allow_data_loss_request, + build_failover_request, + build_get_request, + build_list_by_database_request, + build_list_by_server_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ReplicationLinksOperations: """ .. warning:: @@ -45,54 +60,43 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ReplicationLinkListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ReplicationLink"]: """Gets a list of replication links on database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ReplicationLinkListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ReplicationLinkListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ReplicationLink or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ReplicationLink] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ReplicationLinkListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ReplicationLinkListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -100,17 +104,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -126,10 +120,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -139,52 +131,39 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - link_id: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, link_id: str, **kwargs: Any ) -> _models.ReplicationLink: """Gets a replication link. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param link_id: The name of the replication link. + :param link_id: The name of the replication link. Required. :type link_id: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ReplicationLink, or the result of cls(response) + :return: ReplicationLink or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ReplicationLink - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ReplicationLink] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ReplicationLink] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -192,7 +171,7 @@ async def get( link_id=link_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -200,66 +179,36 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ReplicationLink', pipeline_response) + deserialized = self._deserialize("ReplicationLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}"} # type: ignore - @distributed_trace_async - async def delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - link_id: str, - **kwargs: Any + async def _delete_initial( # pylint: disable=inconsistent-return-statements + self, resource_group_name: str, server_name: str, database_name: str, link_id: str, **kwargs: Any ) -> None: - """Deletes the replication link. - - :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. - :type resource_group_name: str - :param server_name: The name of the server. - :type server_name: str - :param database_name: The name of the database. - :type database_name: str - :param link_id: - :type link_id: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -267,7 +216,7 @@ async def delete( # pylint: disable=inconsistent-return-statements link_id=link_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -275,50 +224,110 @@ async def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response - if response.status_code not in [200]: + if response.status_code not in [200, 202]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}"} # type: ignore + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}"} # type: ignore + + @distributed_trace_async + async def begin_delete( + self, resource_group_name: str, server_name: str, database_name: str, link_id: str, **kwargs: Any + ) -> AsyncLROPoller[None]: + """Deletes the replication link. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param link_id: Required. + :type link_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: + """ + _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: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + if cont_token is None: + raw_result = await self._delete_initial( # type: ignore + resource_group_name=resource_group_name, + server_name=server_name, + database_name=database_name, + link_id=link_id, + api_version=api_version, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements + if cls: + return cls(pipeline_response, None, {}) + + if polling is True: + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling + if cont_token: + return AsyncLROPoller.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.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}"} # type: ignore async def _failover_initial( - self, - resource_group_name: str, - server_name: str, - database_name: str, - link_id: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, link_id: str, **kwargs: Any ) -> Optional[_models.ReplicationLink]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ReplicationLink]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ReplicationLink]] - - request = build_failover_request_initial( + request = build_failover_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, link_id=link_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._failover_initial.metadata['url'], + template_url=self._failover_initial.metadata["url"], headers=_headers, params=_params, ) @@ -326,10 +335,9 @@ async def _failover_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -338,39 +346,30 @@ async def _failover_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ReplicationLink', pipeline_response) + deserialized = self._deserialize("ReplicationLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _failover_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/failover"} # type: ignore - + _failover_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/failover"} # type: ignore @distributed_trace_async async def begin_failover( - self, - resource_group_name: str, - server_name: str, - database_name: str, - link_id: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, link_id: str, **kwargs: Any ) -> AsyncLROPoller[_models.ReplicationLink]: """Fails over from the current primary server to this server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param link_id: The name of the replication link. + :param link_id: The name of the replication link. Required. :type link_id: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -382,19 +381,16 @@ async def begin_failover( :return: An instance of AsyncLROPoller that returns either ReplicationLink or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ReplicationLink] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ReplicationLink] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ReplicationLink] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._failover_initial( # type: ignore resource_group_name=resource_group_name, @@ -402,68 +398,56 @@ async def begin_failover( database_name=database_name, link_id=link_id, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ReplicationLink', pipeline_response) + deserialized = self._deserialize("ReplicationLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_failover.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/failover"} # type: ignore + begin_failover.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/failover"} # type: ignore async def _failover_allow_data_loss_initial( - self, - resource_group_name: str, - server_name: str, - database_name: str, - link_id: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, link_id: str, **kwargs: Any ) -> Optional[_models.ReplicationLink]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ReplicationLink]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ReplicationLink]] - - request = build_failover_allow_data_loss_request_initial( + request = build_failover_allow_data_loss_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, link_id=link_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._failover_allow_data_loss_initial.metadata['url'], + template_url=self._failover_allow_data_loss_initial.metadata["url"], headers=_headers, params=_params, ) @@ -471,10 +455,9 @@ async def _failover_allow_data_loss_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -483,39 +466,30 @@ async def _failover_allow_data_loss_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ReplicationLink', pipeline_response) + deserialized = self._deserialize("ReplicationLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _failover_allow_data_loss_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/forceFailoverAllowDataLoss"} # type: ignore - + _failover_allow_data_loss_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/forceFailoverAllowDataLoss"} # type: ignore @distributed_trace_async async def begin_failover_allow_data_loss( - self, - resource_group_name: str, - server_name: str, - database_name: str, - link_id: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, link_id: str, **kwargs: Any ) -> AsyncLROPoller[_models.ReplicationLink]: """Fails over from the current primary server to this server allowing data loss. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param link_id: The name of the replication link. + :param link_id: The name of the replication link. Required. :type link_id: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -527,19 +501,16 @@ async def begin_failover_allow_data_loss( :return: An instance of AsyncLROPoller that returns either ReplicationLink or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ReplicationLink] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ReplicationLink] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ReplicationLink] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._failover_allow_data_loss_initial( # type: ignore resource_group_name=resource_group_name, @@ -547,83 +518,70 @@ async def begin_failover_allow_data_loss( database_name=database_name, link_id=link_id, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ReplicationLink', pipeline_response) + deserialized = self._deserialize("ReplicationLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_failover_allow_data_loss.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/forceFailoverAllowDataLoss"} # type: ignore + begin_failover_allow_data_loss.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/forceFailoverAllowDataLoss"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ReplicationLinkListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ReplicationLink"]: """Gets a list of replication links. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ReplicationLinkListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ReplicationLinkListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ReplicationLink or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ReplicationLink] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ReplicationLinkListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ReplicationLinkListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -631,16 +589,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -656,10 +605,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -669,8 +616,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/replicationLinks"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/replicationLinks"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_restorable_dropped_databases_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_restorable_dropped_databases_operations.py index 14f4c4a284415..b6a9f999c9892 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_restorable_dropped_databases_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_restorable_dropped_databases_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._restorable_dropped_databases_operations import build_get_request, build_list_by_server_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class RestorableDroppedDatabasesOperations: """ .. warning:: @@ -43,50 +51,42 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.RestorableDroppedDatabaseListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.RestorableDroppedDatabase"]: """Gets a list of restorable dropped databases. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either RestorableDroppedDatabaseListResult or the result - of cls(response) + :return: An iterator like instance of either RestorableDroppedDatabase or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.RestorableDroppedDatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.RestorableDroppedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RestorableDroppedDatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RestorableDroppedDatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -94,16 +94,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -119,10 +110,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -132,56 +121,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/restorableDroppedDatabases"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/restorableDroppedDatabases"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - restorable_dropped_database_id: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, restorable_dropped_database_id: str, **kwargs: Any ) -> _models.RestorableDroppedDatabase: """Gets a restorable dropped database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param restorable_dropped_database_id: + :param restorable_dropped_database_id: Required. :type restorable_dropped_database_id: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: RestorableDroppedDatabase, or the result of cls(response) + :return: RestorableDroppedDatabase or the result of cls(response) :rtype: ~azure.mgmt.sql.models.RestorableDroppedDatabase - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RestorableDroppedDatabase] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RestorableDroppedDatabase] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, restorable_dropped_database_id=restorable_dropped_database_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -189,22 +166,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('RestorableDroppedDatabase', pipeline_response) + deserialized = self._deserialize("RestorableDroppedDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_restorable_dropped_managed_databases_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_restorable_dropped_managed_databases_operations.py index d31e41ae97b44..34b43a052ba37 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_restorable_dropped_managed_databases_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_restorable_dropped_managed_databases_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,15 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._restorable_dropped_managed_databases_operations import build_get_request, build_list_by_instance_request -T = TypeVar('T') +from ...operations._restorable_dropped_managed_databases_operations import ( + build_get_request, + build_list_by_instance_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class RestorableDroppedManagedDatabasesOperations: """ .. warning:: @@ -43,50 +54,42 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.RestorableDroppedManagedDatabaseListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.RestorableDroppedManagedDatabase"]: """Gets a list of restorable dropped managed databases. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either RestorableDroppedManagedDatabaseListResult or the - result of cls(response) + :return: An iterator like instance of either RestorableDroppedManagedDatabase or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.RestorableDroppedManagedDatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.RestorableDroppedManagedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RestorableDroppedManagedDatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RestorableDroppedManagedDatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -94,16 +97,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -119,10 +113,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -132,56 +124,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - managed_instance_name: str, - restorable_dropped_database_id: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, restorable_dropped_database_id: str, **kwargs: Any ) -> _models.RestorableDroppedManagedDatabase: """Gets a restorable dropped managed database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param restorable_dropped_database_id: + :param restorable_dropped_database_id: Required. :type restorable_dropped_database_id: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: RestorableDroppedManagedDatabase, or the result of cls(response) + :return: RestorableDroppedManagedDatabase or the result of cls(response) :rtype: ~azure.mgmt.sql.models.RestorableDroppedManagedDatabase - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RestorableDroppedManagedDatabase] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RestorableDroppedManagedDatabase] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, restorable_dropped_database_id=restorable_dropped_database_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -189,22 +169,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('RestorableDroppedManagedDatabase', pipeline_response) + deserialized = self._deserialize("RestorableDroppedManagedDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_restore_points_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_restore_points_operations.py index b79db88582256..b62dd570f636e 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_restore_points_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_restore_points_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._restore_points_operations import build_create_request_initial, build_delete_request, build_get_request, build_list_by_database_request -T = TypeVar('T') +from ...operations._restore_points_operations import ( + build_create_request, + build_delete_request, + build_get_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class RestorePointsOperations: """ .. warning:: @@ -45,53 +58,43 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.RestorePointListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.RestorePoint"]: """Gets a list of database restore points. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either RestorePointListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.RestorePointListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either RestorePoint or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.RestorePoint] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RestorePointListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RestorePointListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -99,17 +102,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -125,10 +118,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -138,35 +129,37 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints"} # type: ignore async def _create_initial( self, resource_group_name: str, server_name: str, database_name: str, - parameters: _models.CreateDatabaseRestorePointDefinition, + parameters: Union[_models.CreateDatabaseRestorePointDefinition, IO], **kwargs: Any ) -> Optional[_models.RestorePoint]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.RestorePoint]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.RestorePoint]] - _json = self._serialize.body(parameters, 'CreateDatabaseRestorePointDefinition') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "CreateDatabaseRestorePointDefinition") - request = build_create_request_initial( + request = build_create_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -174,7 +167,8 @@ async def _create_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_initial.metadata['url'], + content=_content, + template_url=self._create_initial.metadata["url"], headers=_headers, params=_params, ) @@ -182,10 +176,9 @@ async def _create_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -194,42 +187,43 @@ async def _create_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('RestorePoint', pipeline_response) + deserialized = self._deserialize("RestorePoint", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('RestorePoint', pipeline_response) + deserialized = self._deserialize("RestorePoint", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints"} # type: ignore - + _create_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints"} # type: ignore - @distributed_trace_async + @overload async def begin_create( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.CreateDatabaseRestorePointDefinition, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.RestorePoint]: """Creates a restore point for a data warehouse. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The definition for creating the restore point of this database. + :param parameters: The definition for creating the restore point of this database. Required. :type parameters: ~azure.mgmt.sql.models.CreateDatabaseRestorePointDefinition - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -241,20 +235,94 @@ async def begin_create( :return: An instance of AsyncLROPoller that returns either RestorePoint or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.RestorePoint] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.RestorePoint]: + """Creates a restore point for a data warehouse. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The definition for creating the restore point of this database. Required. + :type parameters: IO + :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 RestorePoint or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.RestorePoint] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.CreateDatabaseRestorePointDefinition, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.RestorePoint]: + """Creates a restore point for a data warehouse. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The definition for creating the restore point of this database. Is either a + model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.CreateDatabaseRestorePointDefinition 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. + :return: An instance of AsyncLROPoller that returns either RestorePoint or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.RestorePoint] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.RestorePoint] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.RestorePoint] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_initial( # type: ignore resource_group_name=resource_group_name, @@ -263,80 +331,65 @@ async def begin_create( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('RestorePoint', pipeline_response) + deserialized = self._deserialize("RestorePoint", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_create.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints"} # type: ignore + begin_create.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - restore_point_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, restore_point_name: str, **kwargs: Any ) -> _models.RestorePoint: """Gets a restore point. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param restore_point_name: The name of the restore point. + :param restore_point_name: The name of the restore point. Required. :type restore_point_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: RestorePoint, or the result of cls(response) + :return: RestorePoint or the result of cls(response) :rtype: ~azure.mgmt.sql.models.RestorePoint - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RestorePoint] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RestorePoint] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -344,7 +397,7 @@ async def get( restore_point_name=restore_point_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -352,66 +405,53 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('RestorePoint', pipeline_response) + deserialized = self._deserialize("RestorePoint", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints/{restorePointName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints/{restorePointName}"} # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - restore_point_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, restore_point_name: str, **kwargs: Any ) -> None: """Deletes a restore point. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param restore_point_name: The name of the restore point. + :param restore_point_name: The name of the restore point. Required. :type restore_point_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -419,7 +459,7 @@ async def delete( # pylint: disable=inconsistent-return-statements restore_point_name=restore_point_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -427,10 +467,9 @@ async def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -440,5 +479,4 @@ async def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints/{restorePointName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints/{restorePointName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sensitivity_labels_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sensitivity_labels_operations.py index 81edcbe3daf1c..3c9f1eb7ef6fb 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sensitivity_labels_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sensitivity_labels_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,21 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._sensitivity_labels_operations import build_create_or_update_request, build_delete_request, build_disable_recommendation_request, build_enable_recommendation_request, build_get_request, build_list_current_by_database_request, build_list_recommended_by_database_request, build_update_request -T = TypeVar('T') +from ...operations._sensitivity_labels_operations import ( + build_create_or_update_request, + build_delete_request, + build_disable_recommendation_request, + build_enable_recommendation_request, + build_get_request, + build_list_current_by_database_request, + build_list_recommended_by_database_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class SensitivityLabelsOperations: """ .. warning:: @@ -43,7 +60,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_current_by_database( self, @@ -54,56 +70,50 @@ def list_current_by_database( count: Optional[bool] = None, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable[_models.SensitivityLabelListResult]: + ) -> AsyncIterable["_models.SensitivityLabel"]: """Gets the sensitivity labels of a given database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param skip_token: Default value is None. + :param skip_token: Default value is None. :type skip_token: str - :param count: Default value is None. + :param count: Default value is None. :type count: bool :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SensitivityLabelListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SensitivityLabelListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SensitivityLabel or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SensitivityLabel] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SensitivityLabelListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SensitivityLabelListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_current_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, skip_token=skip_token, count=count, filter=filter, - template_url=self.list_current_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_current_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -111,20 +121,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_current_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - skip_token=skip_token, - count=count, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -140,10 +137,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -153,53 +148,117 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_current_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/currentSensitivityLabels"} # type: ignore + list_current_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/currentSensitivityLabels"} # type: ignore - @distributed_trace_async + @overload async def update( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.SensitivityLabelUpdateList, + *, + content_type: str = "application/json", **kwargs: Any ) -> None: """Update sensitivity labels of a given database using an operations batch. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.SensitivityLabelUpdateList - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> None: + """Update sensitivity labels of a given database using an operations batch. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Required. + :type parameters: IO + :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: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.SensitivityLabelUpdateList, IO], + **kwargs: Any + ) -> None: + """Update sensitivity labels of a given database using an operations batch. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.SensitivityLabelUpdateList 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 + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'SensitivityLabelUpdateList') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SensitivityLabelUpdateList") request = build_update_request( resource_group_name=resource_group_name, @@ -209,7 +268,8 @@ async def update( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -217,10 +277,9 @@ async def update( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -230,8 +289,7 @@ async def update( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/currentSensitivityLabels"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/currentSensitivityLabels"} # type: ignore @distributed_trace def list_recommended_by_database( @@ -243,17 +301,17 @@ def list_recommended_by_database( include_disabled_recommendations: Optional[bool] = None, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable[_models.SensitivityLabelListResult]: + ) -> AsyncIterable["_models.SensitivityLabel"]: """Gets the sensitivity labels of a given database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param skip_token: Default value is None. + :param skip_token: Default value is None. :type skip_token: str :param include_disabled_recommendations: Specifies whether to include disabled recommendations or not. Default value is None. @@ -261,39 +319,33 @@ def list_recommended_by_database( :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SensitivityLabelListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SensitivityLabelListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SensitivityLabel or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SensitivityLabel] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SensitivityLabelListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SensitivityLabelListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_recommended_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, skip_token=skip_token, include_disabled_recommendations=include_disabled_recommendations, filter=filter, - template_url=self.list_recommended_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_recommended_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -301,20 +353,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_recommended_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - skip_token=skip_token, - include_disabled_recommendations=include_disabled_recommendations, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -330,10 +369,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -343,11 +380,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_recommended_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/recommendedSensitivityLabels"} # type: ignore + list_recommended_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/recommendedSensitivityLabels"} # type: ignore @distributed_trace_async async def enable_recommendation( # pylint: disable=inconsistent-return-statements @@ -364,42 +399,36 @@ async def enable_recommendation( # pylint: disable=inconsistent-return-statemen on all columns). :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :keyword sensitivity_label_source: Default value is "recommended". Note that overriding this + :keyword sensitivity_label_source: Default value is "recommended". Note that overriding this default value may result in unsupported behavior. :paramtype sensitivity_label_source: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "recommended") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "recommended") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_enable_recommendation_request( resource_group_name=resource_group_name, server_name=server_name, @@ -410,7 +439,7 @@ async def enable_recommendation( # pylint: disable=inconsistent-return-statemen subscription_id=self._config.subscription_id, sensitivity_label_source=sensitivity_label_source, api_version=api_version, - template_url=self.enable_recommendation.metadata['url'], + template_url=self.enable_recommendation.metadata["url"], headers=_headers, params=_params, ) @@ -418,10 +447,9 @@ async def enable_recommendation( # pylint: disable=inconsistent-return-statemen request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -431,8 +459,7 @@ async def enable_recommendation( # pylint: disable=inconsistent-return-statemen if cls: return cls(pipeline_response, None, {}) - enable_recommendation.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/enable"} # type: ignore - + enable_recommendation.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/enable"} # type: ignore @distributed_trace_async async def disable_recommendation( # pylint: disable=inconsistent-return-statements @@ -448,42 +475,36 @@ async def disable_recommendation( # pylint: disable=inconsistent-return-stateme """Disables sensitivity recommendations on a given column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :keyword sensitivity_label_source: Default value is "recommended". Note that overriding this + :keyword sensitivity_label_source: Default value is "recommended". Note that overriding this default value may result in unsupported behavior. :paramtype sensitivity_label_source: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "recommended") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "recommended") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_disable_recommendation_request( resource_group_name=resource_group_name, server_name=server_name, @@ -494,7 +515,7 @@ async def disable_recommendation( # pylint: disable=inconsistent-return-stateme subscription_id=self._config.subscription_id, sensitivity_label_source=sensitivity_label_source, api_version=api_version, - template_url=self.disable_recommendation.metadata['url'], + template_url=self.disable_recommendation.metadata["url"], headers=_headers, params=_params, ) @@ -502,10 +523,9 @@ async def disable_recommendation( # pylint: disable=inconsistent-return-stateme request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -515,8 +535,7 @@ async def disable_recommendation( # pylint: disable=inconsistent-return-stateme if cls: return cls(pipeline_response, None, {}) - disable_recommendation.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/disable"} # type: ignore - + disable_recommendation.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/disable"} # type: ignore @distributed_trace_async async def get( @@ -533,40 +552,35 @@ async def get( """Gets the sensitivity label of a given column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :param sensitivity_label_source: The source of the sensitivity label. + :param sensitivity_label_source: The source of the sensitivity label. Known values are: + "current" and "recommended". Required. :type sensitivity_label_source: str or ~azure.mgmt.sql.models.SensitivityLabelSource - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SensitivityLabel, or the result of cls(response) + :return: SensitivityLabel or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SensitivityLabel - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SensitivityLabel] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SensitivityLabel] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -577,7 +591,7 @@ async def get( sensitivity_label_source=sensitivity_label_source, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -585,27 +599,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SensitivityLabel', pipeline_response) + deserialized = self._deserialize("SensitivityLabel", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, @@ -615,50 +627,141 @@ async def create_or_update( table_name: str, column_name: str, parameters: _models.SensitivityLabel, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.SensitivityLabel: """Creates or updates the sensitivity label of a given column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :param parameters: The column sensitivity label resource. + :param parameters: The column sensitivity label resource. Required. :type parameters: ~azure.mgmt.sql.models.SensitivityLabel + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str :keyword sensitivity_label_source: The source of the sensitivity label. Default value is "current". Note that overriding this default value may result in unsupported behavior. :paramtype sensitivity_label_source: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SensitivityLabel, or the result of cls(response) + :return: SensitivityLabel or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SensitivityLabel - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + schema_name: str, + table_name: str, + column_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.SensitivityLabel: + """Creates or updates the sensitivity label of a given column. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param schema_name: The name of the schema. Required. + :type schema_name: str + :param table_name: The name of the table. Required. + :type table_name: str + :param column_name: The name of the column. Required. + :type column_name: str + :param parameters: The column sensitivity label resource. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword sensitivity_label_source: The source of the sensitivity label. Default value is + "current". Note that overriding this default value may result in unsupported behavior. + :paramtype sensitivity_label_source: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SensitivityLabel or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.SensitivityLabel + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + schema_name: str, + table_name: str, + column_name: str, + parameters: Union[_models.SensitivityLabel, IO], + **kwargs: Any + ) -> _models.SensitivityLabel: + """Creates or updates the sensitivity label of a given column. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param schema_name: The name of the schema. Required. + :type schema_name: str + :param table_name: The name of the table. Required. + :type table_name: str + :param column_name: The name of the column. Required. + :type column_name: str + :param parameters: The column sensitivity label resource. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.SensitivityLabel or IO + :keyword sensitivity_label_source: The source of the sensitivity label. Default value is + "current". Note that overriding this default value may result in unsupported behavior. + :paramtype sensitivity_label_source: str + :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 + :return: SensitivityLabel or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.SensitivityLabel + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "current") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.SensitivityLabel] + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "current") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.SensitivityLabel] - _json = self._serialize.body(parameters, 'SensitivityLabel') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SensitivityLabel") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -672,7 +775,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -680,10 +784,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -691,18 +794,17 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('SensitivityLabel', pipeline_response) + deserialized = self._deserialize("SensitivityLabel", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('SensitivityLabel', pipeline_response) + deserialized = self._deserialize("SensitivityLabel", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -718,42 +820,36 @@ async def delete( # pylint: disable=inconsistent-return-statements """Deletes the sensitivity label of a given column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str :keyword sensitivity_label_source: The source of the sensitivity label. Default value is "current". Note that overriding this default value may result in unsupported behavior. :paramtype sensitivity_label_source: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "current") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "current") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -764,7 +860,7 @@ async def delete( # pylint: disable=inconsistent-return-statements subscription_id=self._config.subscription_id, sensitivity_label_source=sensitivity_label_source, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -772,10 +868,9 @@ async def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -785,5 +880,4 @@ async def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_advanced_threat_protection_settings_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_advanced_threat_protection_settings_operations.py index 78050ccbdbb4e..df16be812f17f 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_advanced_threat_protection_settings_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_advanced_threat_protection_settings_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._server_advanced_threat_protection_settings_operations import build_create_or_update_request_initial, build_get_request, build_list_by_server_request -T = TypeVar('T') +from ...operations._server_advanced_threat_protection_settings_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_server_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServerAdvancedThreatProtectionSettingsOperations: """ .. warning:: @@ -45,50 +57,42 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.LogicalServerAdvancedThreatProtectionListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ServerAdvancedThreatProtection"]: """Get a list of the server's Advanced Threat Protection states. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LogicalServerAdvancedThreatProtectionListResult or - the result of cls(response) + :return: An iterator like instance of either ServerAdvancedThreatProtection or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LogicalServerAdvancedThreatProtectionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LogicalServerAdvancedThreatProtectionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LogicalServerAdvancedThreatProtectionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -96,16 +100,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -121,10 +116,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -134,11 +127,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings"} # type: ignore @distributed_trace_async async def get( @@ -151,40 +142,35 @@ async def get( """Get a server's Advanced Threat Protection state. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. :type advanced_threat_protection_name: str or ~azure.mgmt.sql.models.AdvancedThreatProtectionName - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerAdvancedThreatProtection, or the result of cls(response) + :return: ServerAdvancedThreatProtection or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerAdvancedThreatProtection - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerAdvancedThreatProtection] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerAdvancedThreatProtection] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, advanced_threat_protection_name=advanced_threat_protection_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -192,49 +178,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerAdvancedThreatProtection', pipeline_response) + deserialized = self._deserialize("ServerAdvancedThreatProtection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], - parameters: _models.ServerAdvancedThreatProtection, + parameters: Union[_models.ServerAdvancedThreatProtection, IO], **kwargs: Any ) -> Optional[_models.ServerAdvancedThreatProtection]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerAdvancedThreatProtection]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerAdvancedThreatProtection]] - _json = self._serialize.body(parameters, 'ServerAdvancedThreatProtection') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerAdvancedThreatProtection") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, advanced_threat_protection_name=advanced_threat_protection_name, @@ -242,7 +230,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -250,10 +239,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -262,40 +250,125 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerAdvancedThreatProtection', pipeline_response) + deserialized = self._deserialize("ServerAdvancedThreatProtection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], parameters: _models.ServerAdvancedThreatProtection, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ServerAdvancedThreatProtection]: """Creates or updates an Advanced Threat Protection state. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. :type advanced_threat_protection_name: str or ~azure.mgmt.sql.models.AdvancedThreatProtectionName - :param parameters: The server Advanced Threat Protection state. + :param parameters: The server Advanced Threat Protection state. Required. :type parameters: ~azure.mgmt.sql.models.ServerAdvancedThreatProtection - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ServerAdvancedThreatProtection or + the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerAdvancedThreatProtection]: + """Creates or updates an Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The server Advanced Threat Protection state. Required. + :type parameters: IO + :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 ServerAdvancedThreatProtection or + the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: Union[_models.ServerAdvancedThreatProtection, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerAdvancedThreatProtection]: + """Creates or updates an Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The server Advanced Threat Protection state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerAdvancedThreatProtection 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 @@ -308,20 +381,17 @@ async def begin_create_or_update( the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerAdvancedThreatProtection] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerAdvancedThreatProtection] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerAdvancedThreatProtection] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -330,36 +400,32 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerAdvancedThreatProtection', pipeline_response) + deserialized = self._deserialize("ServerAdvancedThreatProtection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_advisors_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_advisors_operations.py index 6856d59136f84..a6d6c77e21f90 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_advisors_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_advisors_operations.py @@ -6,9 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, List, Optional, TypeVar - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, List, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -18,10 +24,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._server_advisors_operations import build_get_request, build_list_by_server_request, build_update_request -T = TypeVar('T') +from ...operations._server_advisors_operations import ( + build_get_request, + build_list_by_server_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServerAdvisorsOperations: """ .. warning:: @@ -41,51 +53,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def list_by_server( - self, - resource_group_name: str, - server_name: str, - expand: Optional[str] = None, - **kwargs: Any + self, resource_group_name: str, server_name: str, expand: Optional[str] = None, **kwargs: Any ) -> List[_models.Advisor]: """Gets a list of server advisors. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: list of Advisor, or the result of cls(response) + :return: list of Advisor or the result of cls(response) :rtype: list[~azure.mgmt.sql.models.Advisor] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[List[_models.Advisor]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[List[_models.Advisor]] - request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.list_by_server.metadata['url'], + api_version=api_version, + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -93,70 +94,58 @@ async def list_by_server( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('[Advisor]', pipeline_response) + deserialized = self._deserialize("[Advisor]", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors"} # type: ignore - + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - advisor_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, advisor_name: str, **kwargs: Any ) -> _models.Advisor: """Gets a server advisor. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param advisor_name: The name of the Server Advisor. + :param advisor_name: The name of the Server Advisor. Required. :type advisor_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Advisor, or the result of cls(response) + :return: Advisor or the result of cls(response) :rtype: ~azure.mgmt.sql.models.Advisor - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.Advisor] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.Advisor] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, advisor_name=advisor_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -164,67 +153,132 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('Advisor', pipeline_response) + deserialized = self._deserialize("Advisor", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors/{advisorName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors/{advisorName}"} # type: ignore - @distributed_trace_async + @overload async def update( self, resource_group_name: str, server_name: str, advisor_name: str, parameters: _models.Advisor, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.Advisor: """Updates a server advisor. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param advisor_name: The name of the Server Advisor. + :param advisor_name: The name of the Server Advisor. Required. :type advisor_name: str - :param parameters: The requested advisor resource state. + :param parameters: The requested advisor resource state. Required. :type parameters: ~azure.mgmt.sql.models.Advisor - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: Advisor, or the result of cls(response) + :return: Advisor or the result of cls(response) :rtype: ~azure.mgmt.sql.models.Advisor - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def update( + self, + resource_group_name: str, + server_name: str, + advisor_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.Advisor: + """Updates a server advisor. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param advisor_name: The name of the Server Advisor. Required. + :type advisor_name: str + :param parameters: The requested advisor resource state. Required. + :type parameters: IO + :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: Advisor or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.Advisor + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def update( + self, + resource_group_name: str, + server_name: str, + advisor_name: str, + parameters: Union[_models.Advisor, IO], + **kwargs: Any + ) -> _models.Advisor: + """Updates a server advisor. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param advisor_name: The name of the Server Advisor. Required. + :type advisor_name: str + :param parameters: The requested advisor resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.Advisor 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 + :return: Advisor or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.Advisor + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.Advisor] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.Advisor] - _json = self._serialize.body(parameters, 'Advisor') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "Advisor") request = build_update_request( resource_group_name=resource_group_name, @@ -234,7 +288,8 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -242,22 +297,20 @@ async def update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('Advisor', pipeline_response) + deserialized = self._deserialize("Advisor", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors/{advisorName}"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors/{advisorName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_automatic_tuning_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_automatic_tuning_operations.py index b70238476595a..21428d51b2738 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_automatic_tuning_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_automatic_tuning_operations.py @@ -6,9 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -19,9 +25,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._server_automatic_tuning_operations import build_get_request, build_update_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServerAutomaticTuningOperations: """ .. warning:: @@ -41,47 +49,35 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async - async def get( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> _models.ServerAutomaticTuning: + async def get(self, resource_group_name: str, server_name: str, **kwargs: Any) -> _models.ServerAutomaticTuning: """Retrieves server automatic tuning options. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerAutomaticTuning, or the result of cls(response) + :return: ServerAutomaticTuning or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerAutomaticTuning - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerAutomaticTuning] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerAutomaticTuning] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -89,64 +85,123 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerAutomaticTuning', pipeline_response) + deserialized = self._deserialize("ServerAutomaticTuning", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/automaticTuning/current"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/automaticTuning/current"} # type: ignore - @distributed_trace_async + @overload async def update( self, resource_group_name: str, server_name: str, parameters: _models.ServerAutomaticTuning, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.ServerAutomaticTuning: """Update automatic tuning options on server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param parameters: The requested automatic tuning resource state. + :param parameters: The requested automatic tuning resource state. Required. :type parameters: ~azure.mgmt.sql.models.ServerAutomaticTuning - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: ServerAutomaticTuning, or the result of cls(response) + :return: ServerAutomaticTuning or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerAutomaticTuning - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def update( + self, + resource_group_name: str, + server_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.ServerAutomaticTuning: + """Update automatic tuning options on server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The requested automatic tuning resource state. Required. + :type parameters: IO + :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: ServerAutomaticTuning or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ServerAutomaticTuning + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def update( + self, + resource_group_name: str, + server_name: str, + parameters: Union[_models.ServerAutomaticTuning, IO], + **kwargs: Any + ) -> _models.ServerAutomaticTuning: + """Update automatic tuning options on server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The requested automatic tuning resource state. Is either a model type or a + IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerAutomaticTuning 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 + :return: ServerAutomaticTuning or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ServerAutomaticTuning + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerAutomaticTuning] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerAutomaticTuning] - _json = self._serialize.body(parameters, 'ServerAutomaticTuning') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerAutomaticTuning") request = build_update_request( resource_group_name=resource_group_name, @@ -155,7 +210,8 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -163,22 +219,20 @@ async def update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerAutomaticTuning', pipeline_response) + deserialized = self._deserialize("ServerAutomaticTuning", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/automaticTuning/current"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/automaticTuning/current"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_azure_ad_administrators_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_azure_ad_administrators_operations.py index d76f6468f242e..a9ae2455a7fa5 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_azure_ad_administrators_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_azure_ad_administrators_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._server_azure_ad_administrators_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_server_request -T = TypeVar('T') +from ...operations._server_azure_ad_administrators_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_server_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServerAzureADAdministratorsOperations: """ .. warning:: @@ -45,7 +58,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -57,39 +69,34 @@ async def get( """Gets a Azure Active Directory administrator. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param administrator_name: The name of server active directory administrator. + :param administrator_name: The name of server active directory administrator. "ActiveDirectory" + Required. :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerAzureADAdministrator, or the result of cls(response) + :return: ServerAzureADAdministrator or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerAzureADAdministrator - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerAzureADAdministrator] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerAzureADAdministrator] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, administrator_name=administrator_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,49 +104,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerAzureADAdministrator', pipeline_response) + deserialized = self._deserialize("ServerAzureADAdministrator", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, administrator_name: Union[str, "_models.AdministratorName"], - parameters: _models.ServerAzureADAdministrator, + parameters: Union[_models.ServerAzureADAdministrator, IO], **kwargs: Any ) -> Optional[_models.ServerAzureADAdministrator]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerAzureADAdministrator]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerAzureADAdministrator]] - _json = self._serialize.body(parameters, 'ServerAzureADAdministrator') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerAzureADAdministrator") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, administrator_name=administrator_name, @@ -147,7 +156,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -155,10 +165,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -167,42 +176,123 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerAzureADAdministrator', pipeline_response) + deserialized = self._deserialize("ServerAzureADAdministrator", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ServerAzureADAdministrator', pipeline_response) + deserialized = self._deserialize("ServerAzureADAdministrator", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, administrator_name: Union[str, "_models.AdministratorName"], parameters: _models.ServerAzureADAdministrator, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ServerAzureADAdministrator]: """Creates or updates an existing Azure Active Directory administrator. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param administrator_name: The name of server active directory administrator. + :param administrator_name: The name of server active directory administrator. "ActiveDirectory" + Required. :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName - :param parameters: The requested Azure Active Directory administrator Resource state. + :param parameters: The requested Azure Active Directory administrator Resource state. Required. :type parameters: ~azure.mgmt.sql.models.ServerAzureADAdministrator - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ServerAzureADAdministrator or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerAzureADAdministrator] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + administrator_name: Union[str, "_models.AdministratorName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerAzureADAdministrator]: + """Creates or updates an existing Azure Active Directory administrator. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param administrator_name: The name of server active directory administrator. "ActiveDirectory" + Required. + :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName + :param parameters: The requested Azure Active Directory administrator Resource state. Required. + :type parameters: IO + :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 ServerAzureADAdministrator or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerAzureADAdministrator] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + administrator_name: Union[str, "_models.AdministratorName"], + parameters: Union[_models.ServerAzureADAdministrator, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerAzureADAdministrator]: + """Creates or updates an existing Azure Active Directory administrator. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param administrator_name: The name of server active directory administrator. "ActiveDirectory" + Required. + :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName + :param parameters: The requested Azure Active Directory administrator Resource state. Is either + a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerAzureADAdministrator 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 @@ -214,20 +304,17 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either ServerAzureADAdministrator or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerAzureADAdministrator] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerAzureADAdministrator] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerAzureADAdministrator] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -236,39 +323,35 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerAzureADAdministrator', pipeline_response) + deserialized = self._deserialize("ServerAzureADAdministrator", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements self, @@ -277,25 +360,22 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements administrator_name: Union[str, "_models.AdministratorName"], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, administrator_name=administrator_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -303,10 +383,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -316,11 +395,10 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements + async def begin_delete( self, resource_group_name: str, server_name: str, @@ -330,15 +408,13 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements """Deletes the Azure Active Directory administrator with the given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param administrator_name: The name of server active directory administrator. + :param administrator_name: The name of server active directory administrator. "ActiveDirectory" + Required. :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -349,99 +425,86 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, administrator_name=administrator_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.AdministratorListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ServerAzureADAdministrator"]: """Gets a list of Azure Active Directory administrators in a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either AdministratorListResult or the result of + :return: An iterator like instance of either ServerAzureADAdministrator or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.AdministratorListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerAzureADAdministrator] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.AdministratorListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.AdministratorListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -449,16 +512,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -474,10 +528,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -487,8 +539,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_azure_ad_only_authentications_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_azure_ad_only_authentications_operations.py index d095d010d64ce..79dbb020eb8d2 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_azure_ad_only_authentications_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_azure_ad_only_authentications_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._server_azure_ad_only_authentications_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_server_request -T = TypeVar('T') +from ...operations._server_azure_ad_only_authentications_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_server_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServerAzureADOnlyAuthenticationsOperations: """ .. warning:: @@ -45,7 +58,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -57,39 +69,34 @@ async def get( """Gets a specific Azure Active Directory only authentication property. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerAzureADOnlyAuthentication, or the result of cls(response) + :return: ServerAzureADOnlyAuthentication or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerAzureADOnlyAuthentication - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerAzureADOnlyAuthentication] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerAzureADOnlyAuthentication] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, authentication_name=authentication_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,49 +104,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerAzureADOnlyAuthentication', pipeline_response) + deserialized = self._deserialize("ServerAzureADOnlyAuthentication", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, authentication_name: Union[str, "_models.AuthenticationName"], - parameters: _models.ServerAzureADOnlyAuthentication, + parameters: Union[_models.ServerAzureADOnlyAuthentication, IO], **kwargs: Any ) -> Optional[_models.ServerAzureADOnlyAuthentication]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerAzureADOnlyAuthentication]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerAzureADOnlyAuthentication]] - _json = self._serialize.body(parameters, 'ServerAzureADOnlyAuthentication') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerAzureADOnlyAuthentication") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, authentication_name=authentication_name, @@ -147,7 +156,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -155,10 +165,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -167,44 +176,130 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerAzureADOnlyAuthentication', pipeline_response) + deserialized = self._deserialize("ServerAzureADOnlyAuthentication", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ServerAzureADOnlyAuthentication', pipeline_response) + deserialized = self._deserialize("ServerAzureADOnlyAuthentication", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, authentication_name: Union[str, "_models.AuthenticationName"], parameters: _models.ServerAzureADOnlyAuthentication, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ServerAzureADOnlyAuthentication]: """Sets Server Active Directory only authentication property or updates an existing server Active Directory only authentication property. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName :param parameters: The required parameters for creating or updating an Active Directory only - authentication property. + authentication property. Required. :type parameters: ~azure.mgmt.sql.models.ServerAzureADOnlyAuthentication - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ServerAzureADOnlyAuthentication or + the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerAzureADOnlyAuthentication] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + authentication_name: Union[str, "_models.AuthenticationName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerAzureADOnlyAuthentication]: + """Sets Server Active Directory only authentication property or updates an existing server Active + Directory only authentication property. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. + :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName + :param parameters: The required parameters for creating or updating an Active Directory only + authentication property. Required. + :type parameters: IO + :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 ServerAzureADOnlyAuthentication or + the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerAzureADOnlyAuthentication] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + authentication_name: Union[str, "_models.AuthenticationName"], + parameters: Union[_models.ServerAzureADOnlyAuthentication, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerAzureADOnlyAuthentication]: + """Sets Server Active Directory only authentication property or updates an existing server Active + Directory only authentication property. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. + :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName + :param parameters: The required parameters for creating or updating an Active Directory only + authentication property. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerAzureADOnlyAuthentication 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 @@ -217,20 +312,17 @@ async def begin_create_or_update( the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerAzureADOnlyAuthentication] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerAzureADOnlyAuthentication] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerAzureADOnlyAuthentication] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -239,39 +331,35 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerAzureADOnlyAuthentication', pipeline_response) + deserialized = self._deserialize("ServerAzureADOnlyAuthentication", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements self, @@ -280,25 +368,22 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements authentication_name: Union[str, "_models.AuthenticationName"], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, authentication_name=authentication_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -306,10 +391,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -319,11 +403,10 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements + async def begin_delete( self, resource_group_name: str, server_name: str, @@ -333,15 +416,13 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements """Deletes an existing server Active Directory only authentication property. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -352,100 +433,86 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, authentication_name=authentication_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.AzureADOnlyAuthListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ServerAzureADOnlyAuthentication"]: """Gets a list of server Azure Active Directory only authentications. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either AzureADOnlyAuthListResult or the result of + :return: An iterator like instance of either ServerAzureADOnlyAuthentication or the result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.AzureADOnlyAuthListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerAzureADOnlyAuthentication] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.AzureADOnlyAuthListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.AzureADOnlyAuthListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -453,16 +520,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -478,10 +536,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -491,8 +547,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_blob_auditing_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_blob_auditing_policies_operations.py index 3ebd0721ab5f0..1d92072d1ae8b 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_blob_auditing_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_blob_auditing_policies_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._server_blob_auditing_policies_operations import build_create_or_update_request_initial, build_get_request, build_list_by_server_request -T = TypeVar('T') +from ...operations._server_blob_auditing_policies_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_server_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServerBlobAuditingPoliciesOperations: """ .. warning:: @@ -45,50 +57,42 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ServerBlobAuditingPolicyListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ServerBlobAuditingPolicy"]: """Lists auditing settings of a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerBlobAuditingPolicyListResult or the result - of cls(response) + :return: An iterator like instance of either ServerBlobAuditingPolicy or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerBlobAuditingPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerBlobAuditingPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerBlobAuditingPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerBlobAuditingPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -96,16 +100,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -121,10 +116,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -134,57 +127,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings"} # type: ignore @distributed_trace_async - async def get( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> _models.ServerBlobAuditingPolicy: + async def get(self, resource_group_name: str, server_name: str, **kwargs: Any) -> _models.ServerBlobAuditingPolicy: """Gets a server's blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is "default". Note that overriding this default value may result in unsupported behavior. :paramtype blob_auditing_policy_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerBlobAuditingPolicy, or the result of cls(response) + :return: ServerBlobAuditingPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerBlobAuditingPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerBlobAuditingPolicy] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerBlobAuditingPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, blob_auditing_policy_name=blob_auditing_policy_name, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -192,49 +172,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ServerBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, - parameters: _models.ServerBlobAuditingPolicy, + parameters: Union[_models.ServerBlobAuditingPolicy, IO], **kwargs: Any ) -> Optional[_models.ServerBlobAuditingPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerBlobAuditingPolicy]] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerBlobAuditingPolicy]] - _json = self._serialize.body(parameters, 'ServerBlobAuditingPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerBlobAuditingPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, @@ -242,7 +224,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -250,10 +233,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -262,39 +244,40 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ServerBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, parameters: _models.ServerBlobAuditingPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ServerBlobAuditingPolicy]: """Creates or updates a server's blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param parameters: Properties of blob auditing policy. + :param parameters: Properties of blob auditing policy. Required. :type parameters: ~azure.mgmt.sql.models.ServerBlobAuditingPolicy + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is "default". Note that overriding this default value may result in unsupported behavior. :paramtype blob_auditing_policy_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -306,21 +289,95 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either ServerBlobAuditingPolicy or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerBlobAuditingPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerBlobAuditingPolicy]: + """Creates or updates a server's blob auditing policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: Properties of blob auditing policy. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is + "default". Note that overriding this default value may result in unsupported behavior. + :paramtype blob_auditing_policy_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 ServerBlobAuditingPolicy or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerBlobAuditingPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + parameters: Union[_models.ServerBlobAuditingPolicy, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerBlobAuditingPolicy]: + """Creates or updates a server's blob auditing policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: Properties of blob auditing policy. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ServerBlobAuditingPolicy or IO + :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is + "default". Note that overriding this default value may result in unsupported behavior. + :paramtype blob_auditing_policy_name: str + :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. + :return: An instance of AsyncLROPoller that returns either ServerBlobAuditingPolicy or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerBlobAuditingPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerBlobAuditingPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerBlobAuditingPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -329,36 +386,32 @@ async def begin_create_or_update( blob_auditing_policy_name=blob_auditing_policy_name, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ServerBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_communication_links_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_communication_links_operations.py index b1e2a3d43ebb4..16171db30a4ec 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_communication_links_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_communication_links_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._server_communication_links_operations import build_create_or_update_request_initial, build_delete_request, build_get_request, build_list_by_server_request -T = TypeVar('T') +from ...operations._server_communication_links_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_server_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServerCommunicationLinksOperations: """ .. warning:: @@ -45,51 +58,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - communication_link_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, communication_link_name: str, **kwargs: Any ) -> None: """Deletes a server communication link. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param communication_link_name: The name of the server communication link. + :param communication_link_name: The name of the server communication link. Required. :type communication_link_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, communication_link_name=communication_link_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -97,10 +99,9 @@ async def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -110,53 +111,42 @@ async def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - communication_link_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, communication_link_name: str, **kwargs: Any ) -> _models.ServerCommunicationLink: """Returns a server communication link. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param communication_link_name: The name of the server communication link. + :param communication_link_name: The name of the server communication link. Required. :type communication_link_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerCommunicationLink, or the result of cls(response) + :return: ServerCommunicationLink or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerCommunicationLink - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerCommunicationLink] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerCommunicationLink] - request = build_get_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, communication_link_name=communication_link_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -164,57 +154,60 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerCommunicationLink', pipeline_response) + deserialized = self._deserialize("ServerCommunicationLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, communication_link_name: str, - parameters: _models.ServerCommunicationLink, + parameters: Union[_models.ServerCommunicationLink, IO], **kwargs: Any ) -> Optional[_models.ServerCommunicationLink]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerCommunicationLink]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerCommunicationLink]] - _json = self._serialize.body(parameters, 'ServerCommunicationLink') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerCommunicationLink") - request = build_create_or_update_request_initial( - subscription_id=self._config.subscription_id, + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, communication_link_name=communication_link_name, + subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -222,10 +215,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [201, 202]: @@ -234,39 +226,117 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 201: - deserialized = self._deserialize('ServerCommunicationLink', pipeline_response) + deserialized = self._deserialize("ServerCommunicationLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, communication_link_name: str, parameters: _models.ServerCommunicationLink, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ServerCommunicationLink]: """Creates a server communication link. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param communication_link_name: The name of the server communication link. + :param communication_link_name: The name of the server communication link. Required. :type communication_link_name: str - :param parameters: The required parameters for creating a server communication link. + :param parameters: The required parameters for creating a server communication link. Required. :type parameters: ~azure.mgmt.sql.models.ServerCommunicationLink - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str + :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 ServerCommunicationLink or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerCommunicationLink] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + communication_link_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerCommunicationLink]: + """Creates a server communication link. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param communication_link_name: The name of the server communication link. Required. + :type communication_link_name: str + :param parameters: The required parameters for creating a server communication link. Required. + :type parameters: IO + :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 ServerCommunicationLink or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerCommunicationLink] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + communication_link_name: str, + parameters: Union[_models.ServerCommunicationLink, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerCommunicationLink]: + """Creates a server communication link. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param communication_link_name: The name of the server communication link. Required. + :type communication_link_name: str + :param parameters: The required parameters for creating a server communication link. Is either + a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerCommunicationLink 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 @@ -278,20 +348,17 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either ServerCommunicationLink or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerCommunicationLink] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerCommunicationLink] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerCommunicationLink] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -300,83 +367,71 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerCommunicationLink', pipeline_response) + deserialized = self._deserialize("ServerCommunicationLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ServerCommunicationLinkListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ServerCommunicationLink"]: """Gets a list of server communication links. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerCommunicationLinkListResult or the result of + :return: An iterator like instance of either ServerCommunicationLink or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerCommunicationLinkListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerCommunicationLink] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerCommunicationLinkListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerCommunicationLinkListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -384,16 +439,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -409,10 +455,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -422,8 +466,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_connection_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_connection_policies_operations.py index af2e801f4c43f..378976376558d 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_connection_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_connection_policies_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._server_connection_policies_operations import build_create_or_update_request_initial, build_get_request, build_list_by_server_request -T = TypeVar('T') +from ...operations._server_connection_policies_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_server_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServerConnectionPoliciesOperations: """ .. warning:: @@ -45,7 +57,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -57,39 +68,33 @@ async def get( """Gets a server connection policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param connection_policy_name: The name of the connection policy. + :param connection_policy_name: The name of the connection policy. "default" Required. :type connection_policy_name: str or ~azure.mgmt.sql.models.ConnectionPolicyName - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerConnectionPolicy, or the result of cls(response) + :return: ServerConnectionPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerConnectionPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerConnectionPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerConnectionPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, connection_policy_name=connection_policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,49 +102,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerConnectionPolicy', pipeline_response) + deserialized = self._deserialize("ServerConnectionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, connection_policy_name: Union[str, "_models.ConnectionPolicyName"], - parameters: _models.ServerConnectionPolicy, + parameters: Union[_models.ServerConnectionPolicy, IO], **kwargs: Any ) -> Optional[_models.ServerConnectionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerConnectionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerConnectionPolicy]] - _json = self._serialize.body(parameters, 'ServerConnectionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerConnectionPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, connection_policy_name=connection_policy_name, @@ -147,7 +154,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -155,10 +163,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -167,39 +174,40 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerConnectionPolicy', pipeline_response) + deserialized = self._deserialize("ServerConnectionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, connection_policy_name: Union[str, "_models.ConnectionPolicyName"], parameters: _models.ServerConnectionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ServerConnectionPolicy]: """Updates a server connection policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param connection_policy_name: The name of the connection policy. + :param connection_policy_name: The name of the connection policy. "default" Required. :type connection_policy_name: str or ~azure.mgmt.sql.models.ConnectionPolicyName - :param parameters: The required parameters for updating a server connection policy. + :param parameters: The required parameters for updating a server connection policy. Required. :type parameters: ~azure.mgmt.sql.models.ServerConnectionPolicy - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -211,20 +219,94 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either ServerConnectionPolicy or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerConnectionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + connection_policy_name: Union[str, "_models.ConnectionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerConnectionPolicy]: + """Updates a server connection policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param connection_policy_name: The name of the connection policy. "default" Required. + :type connection_policy_name: str or ~azure.mgmt.sql.models.ConnectionPolicyName + :param parameters: The required parameters for updating a server connection policy. Required. + :type parameters: IO + :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 ServerConnectionPolicy or the result + of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerConnectionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + connection_policy_name: Union[str, "_models.ConnectionPolicyName"], + parameters: Union[_models.ServerConnectionPolicy, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerConnectionPolicy]: + """Updates a server connection policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param connection_policy_name: The name of the connection policy. "default" Required. + :type connection_policy_name: str or ~azure.mgmt.sql.models.ConnectionPolicyName + :param parameters: The required parameters for updating a server connection policy. Is either a + model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerConnectionPolicy 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. + :return: An instance of AsyncLROPoller that returns either ServerConnectionPolicy or the result + of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerConnectionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerConnectionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerConnectionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -233,83 +315,71 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerConnectionPolicy', pipeline_response) + deserialized = self._deserialize("ServerConnectionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ServerConnectionPolicyListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ServerConnectionPolicy"]: """Lists connection policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerConnectionPolicyListResult or the result of + :return: An iterator like instance of either ServerConnectionPolicy or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerConnectionPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerConnectionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerConnectionPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerConnectionPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -317,16 +387,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -342,10 +403,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -355,8 +414,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_dev_ops_audit_settings_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_dev_ops_audit_settings_operations.py index 1a8c8feacec94..5d301ac48d305 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_dev_ops_audit_settings_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_dev_ops_audit_settings_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._server_dev_ops_audit_settings_operations import build_create_or_update_request_initial, build_get_request, build_list_by_server_request -T = TypeVar('T') +from ...operations._server_dev_ops_audit_settings_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_server_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServerDevOpsAuditSettingsOperations: """ .. warning:: @@ -45,52 +57,41 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - dev_ops_auditing_settings_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, dev_ops_auditing_settings_name: str, **kwargs: Any ) -> _models.ServerDevOpsAuditingSettings: """Gets a server's DevOps audit settings. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param dev_ops_auditing_settings_name: The name of the devops audit settings. This should - always be 'default'. + always be 'default'. Required. :type dev_ops_auditing_settings_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerDevOpsAuditingSettings, or the result of cls(response) + :return: ServerDevOpsAuditingSettings or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerDevOpsAuditingSettings - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerDevOpsAuditingSettings] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerDevOpsAuditingSettings] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, dev_ops_auditing_settings_name=dev_ops_auditing_settings_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -98,49 +99,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerDevOpsAuditingSettings', pipeline_response) + deserialized = self._deserialize("ServerDevOpsAuditingSettings", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings/{devOpsAuditingSettingsName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings/{devOpsAuditingSettingsName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, dev_ops_auditing_settings_name: str, - parameters: _models.ServerDevOpsAuditingSettings, + parameters: Union[_models.ServerDevOpsAuditingSettings, IO], **kwargs: Any ) -> Optional[_models.ServerDevOpsAuditingSettings]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerDevOpsAuditingSettings]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerDevOpsAuditingSettings]] - _json = self._serialize.body(parameters, 'ServerDevOpsAuditingSettings') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerDevOpsAuditingSettings") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, dev_ops_auditing_settings_name=dev_ops_auditing_settings_name, @@ -148,7 +151,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -156,10 +160,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -168,40 +171,120 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerDevOpsAuditingSettings', pipeline_response) + deserialized = self._deserialize("ServerDevOpsAuditingSettings", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings/{devOpsAuditingSettingsName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings/{devOpsAuditingSettingsName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, dev_ops_auditing_settings_name: str, parameters: _models.ServerDevOpsAuditingSettings, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ServerDevOpsAuditingSettings]: """Creates or updates a server's DevOps audit settings. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param dev_ops_auditing_settings_name: The name of the devops audit settings. This should - always be 'default'. + always be 'default'. Required. :type dev_ops_auditing_settings_name: str - :param parameters: Properties of DevOps audit settings. + :param parameters: Properties of DevOps audit settings. Required. :type parameters: ~azure.mgmt.sql.models.ServerDevOpsAuditingSettings - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ServerDevOpsAuditingSettings or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerDevOpsAuditingSettings] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + dev_ops_auditing_settings_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerDevOpsAuditingSettings]: + """Creates or updates a server's DevOps audit settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param dev_ops_auditing_settings_name: The name of the devops audit settings. This should + always be 'default'. Required. + :type dev_ops_auditing_settings_name: str + :param parameters: Properties of DevOps audit settings. Required. + :type parameters: IO + :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 ServerDevOpsAuditingSettings or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerDevOpsAuditingSettings] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + dev_ops_auditing_settings_name: str, + parameters: Union[_models.ServerDevOpsAuditingSettings, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerDevOpsAuditingSettings]: + """Creates or updates a server's DevOps audit settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param dev_ops_auditing_settings_name: The name of the devops audit settings. This should + always be 'default'. Required. + :type dev_ops_auditing_settings_name: str + :param parameters: Properties of DevOps audit settings. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ServerDevOpsAuditingSettings 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 @@ -213,20 +296,17 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either ServerDevOpsAuditingSettings or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerDevOpsAuditingSettings] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerDevOpsAuditingSettings] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerDevOpsAuditingSettings] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -235,83 +315,75 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerDevOpsAuditingSettings', pipeline_response) + deserialized = self._deserialize("ServerDevOpsAuditingSettings", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - lro_options={'final-state-via': 'azure-async-operation'}, - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast( + AsyncPollingMethod, + AsyncARMPolling(lro_delay, lro_options={"final-state-via": "azure-async-operation"}, **kwargs), + ) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/devOpsAuditingSettings/{devOpsAuditingSettingsName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings/{devOpsAuditingSettingsName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ServerDevOpsAuditSettingsListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ServerDevOpsAuditingSettings"]: """Lists DevOps audit settings of a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerDevOpsAuditSettingsListResult or the result - of cls(response) + :return: An iterator like instance of either ServerDevOpsAuditingSettings or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerDevOpsAuditSettingsListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerDevOpsAuditingSettings] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerDevOpsAuditSettingsListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerDevOpsAuditSettingsListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -319,16 +391,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -344,10 +407,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -357,8 +418,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_dns_aliases_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_dns_aliases_operations.py index 7be9fe8d8f6c8..0d96bbf7c1053 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_dns_aliases_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_dns_aliases_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,18 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._server_dns_aliases_operations import build_acquire_request_initial, build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_server_request -T = TypeVar('T') +from ...operations._server_dns_aliases_operations import ( + build_acquire_request, + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_server_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServerDnsAliasesOperations: """ .. warning:: @@ -45,51 +59,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - dns_alias_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, dns_alias_name: str, **kwargs: Any ) -> _models.ServerDnsAlias: """Gets a server DNS alias. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server that the alias is pointing to. + :param server_name: The name of the server that the alias is pointing to. Required. :type server_name: str - :param dns_alias_name: The name of the server dns alias. + :param dns_alias_name: The name of the server dns alias. Required. :type dns_alias_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerDnsAlias, or the result of cls(response) + :return: ServerDnsAlias or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerDnsAlias - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerDnsAlias] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerDnsAlias] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, dns_alias_name=dns_alias_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,52 +100,43 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore async def _create_or_update_initial( - self, - resource_group_name: str, - server_name: str, - dns_alias_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, dns_alias_name: str, **kwargs: Any ) -> Optional[_models.ServerDnsAlias]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerDnsAlias]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerDnsAlias]] - - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, dns_alias_name=dns_alias_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._create_or_update_initial.metadata['url'], + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -150,10 +144,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -162,39 +155,31 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ServerDnsAlias", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore @distributed_trace_async async def begin_create_or_update( - self, - resource_group_name: str, - server_name: str, - dns_alias_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, dns_alias_name: str, **kwargs: Any ) -> AsyncLROPoller[_models.ServerDnsAlias]: """Creates a server DNS alias. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server that the alias is pointing to. + :param server_name: The name of the server that the alias is pointing to. Required. :type server_name: str - :param dns_alias_name: The name of the server dns alias. + :param dns_alias_name: The name of the server dns alias. Required. :type dns_alias_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -206,85 +191,71 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either ServerDnsAlias or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerDnsAlias] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerDnsAlias] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerDnsAlias] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, dns_alias_name=dns_alias_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - dns_alias_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, dns_alias_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, dns_alias_name=dns_alias_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -292,10 +263,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -305,29 +275,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - dns_alias_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, server_name: str, dns_alias_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes the server DNS alias with the given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server that the alias is pointing to. + :param server_name: The name of the server that the alias is pointing to. Required. :type server_name: str - :param dns_alias_name: The name of the server dns alias. + :param dns_alias_name: The name of the server dns alias. Required. :type dns_alias_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -338,100 +300,84 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, dns_alias_name=dns_alias_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ServerDnsAliasListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ServerDnsAlias"]: """Gets a list of server DNS aliases for a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server that the alias is pointing to. + :param server_name: The name of the server that the alias is pointing to. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerDnsAliasListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerDnsAliasListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServerDnsAlias or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerDnsAlias] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerDnsAliasListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerDnsAliasListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -439,16 +385,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -464,10 +401,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -477,35 +412,37 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases"} # type: ignore async def _acquire_initial( self, resource_group_name: str, server_name: str, dns_alias_name: str, - parameters: _models.ServerDnsAliasAcquisition, + parameters: Union[_models.ServerDnsAliasAcquisition, IO], **kwargs: Any ) -> Optional[_models.ServerDnsAlias]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerDnsAlias]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerDnsAlias]] - _json = self._serialize.body(parameters, 'ServerDnsAliasAcquisition') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerDnsAliasAcquisition") - request = build_acquire_request_initial( + request = build_acquire_request( resource_group_name=resource_group_name, server_name=server_name, dns_alias_name=dns_alias_name, @@ -513,7 +450,8 @@ async def _acquire_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._acquire_initial.metadata['url'], + content=_content, + template_url=self._acquire_initial.metadata["url"], headers=_headers, params=_params, ) @@ -521,10 +459,9 @@ async def _acquire_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -533,39 +470,116 @@ async def _acquire_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _acquire_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}/acquire"} # type: ignore + _acquire_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}/acquire"} # type: ignore - - @distributed_trace_async + @overload async def begin_acquire( self, resource_group_name: str, server_name: str, dns_alias_name: str, parameters: _models.ServerDnsAliasAcquisition, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ServerDnsAlias]: """Acquires server DNS alias from another server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server that the alias is pointing to. + :param server_name: The name of the server that the alias is pointing to. Required. :type server_name: str - :param dns_alias_name: The name of the server dns alias. + :param dns_alias_name: The name of the server dns alias. Required. :type dns_alias_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.ServerDnsAliasAcquisition - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ServerDnsAlias or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerDnsAlias] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_acquire( + self, + resource_group_name: str, + server_name: str, + dns_alias_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerDnsAlias]: + """Acquires server DNS alias from another server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server that the alias is pointing to. Required. + :type server_name: str + :param dns_alias_name: The name of the server dns alias. Required. + :type dns_alias_name: str + :param parameters: Required. + :type parameters: IO + :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 ServerDnsAlias or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerDnsAlias] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_acquire( + self, + resource_group_name: str, + server_name: str, + dns_alias_name: str, + parameters: Union[_models.ServerDnsAliasAcquisition, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerDnsAlias]: + """Acquires server DNS alias from another server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server that the alias is pointing to. Required. + :type server_name: str + :param dns_alias_name: The name of the server dns alias. Required. + :type dns_alias_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerDnsAliasAcquisition 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 @@ -577,20 +591,17 @@ async def begin_acquire( :return: An instance of AsyncLROPoller that returns either ServerDnsAlias or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerDnsAlias] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerDnsAlias] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerDnsAlias] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._acquire_initial( # type: ignore resource_group_name=resource_group_name, @@ -599,36 +610,32 @@ async def begin_acquire( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_acquire.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}/acquire"} # type: ignore + begin_acquire.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}/acquire"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_keys_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_keys_operations.py index dde3edaa3e857..d1b62cb0df51a 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_keys_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_keys_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._server_keys_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_server_request -T = TypeVar('T') +from ...operations._server_keys_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_server_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServerKeysOperations: """ .. warning:: @@ -45,48 +58,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ServerKeyListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ServerKey"]: """Gets a list of server keys. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerKeyListResult or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerKeyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServerKey or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerKey] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerKeyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerKeyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -94,16 +99,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -119,10 +115,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -132,56 +126,42 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys"} # type: ignore @distributed_trace_async - async def get( - self, - resource_group_name: str, - server_name: str, - key_name: str, - **kwargs: Any - ) -> _models.ServerKey: + async def get(self, resource_group_name: str, server_name: str, key_name: str, **kwargs: Any) -> _models.ServerKey: """Gets a server key. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param key_name: The name of the server key to be retrieved. + :param key_name: The name of the server key to be retrieved. Required. :type key_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerKey, or the result of cls(response) + :return: ServerKey or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerKey - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerKey] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerKey] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, key_name=key_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -189,49 +169,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerKey', pipeline_response) + deserialized = self._deserialize("ServerKey", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, key_name: str, - parameters: _models.ServerKey, + parameters: Union[_models.ServerKey, IO], **kwargs: Any ) -> Optional[_models.ServerKey]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerKey]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerKey]] - _json = self._serialize.body(parameters, 'ServerKey') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerKey") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, key_name=key_name, @@ -239,7 +221,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -247,10 +230,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -259,45 +241,46 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerKey', pipeline_response) + deserialized = self._deserialize("ServerKey", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ServerKey', pipeline_response) + deserialized = self._deserialize("ServerKey", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, key_name: str, parameters: _models.ServerKey, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ServerKey]: """Creates or updates a server key. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param key_name: The name of the server key to be operated on (updated or created). The key name is required to be in the format of 'vault_key_version'. For example, if the keyId is https://YourVaultName.vault.azure.net/keys/YourKeyName/YourKeyVersion, then the server key name - should be formatted as: YourVaultName_YourKeyName_YourKeyVersion. + should be formatted as: YourVaultName_YourKeyName_YourKeyVersion. Required. :type key_name: str - :param parameters: The requested server key resource state. + :param parameters: The requested server key resource state. Required. :type parameters: ~azure.mgmt.sql.models.ServerKey - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -309,20 +292,100 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either ServerKey or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerKey] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + key_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerKey]: + """Creates or updates a server key. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param key_name: The name of the server key to be operated on (updated or created). The key + name is required to be in the format of 'vault_key_version'. For example, if the keyId is + https://YourVaultName.vault.azure.net/keys/YourKeyName/YourKeyVersion, then the server key name + should be formatted as: YourVaultName_YourKeyName_YourKeyVersion. Required. + :type key_name: str + :param parameters: The requested server key resource state. Required. + :type parameters: IO + :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 ServerKey or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerKey] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + key_name: str, + parameters: Union[_models.ServerKey, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerKey]: + """Creates or updates a server key. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param key_name: The name of the server key to be operated on (updated or created). The key + name is required to be in the format of 'vault_key_version'. For example, if the keyId is + https://YourVaultName.vault.azure.net/keys/YourKeyName/YourKeyVersion, then the server key name + should be formatted as: YourVaultName_YourKeyName_YourKeyVersion. Required. + :type key_name: str + :param parameters: The requested server key resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerKey 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. + :return: An instance of AsyncLROPoller that returns either ServerKey or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerKey] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerKey] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerKey] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -331,66 +394,55 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerKey', pipeline_response) + deserialized = self._deserialize("ServerKey", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - key_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, key_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, key_name=key_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -398,10 +450,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -411,29 +462,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - key_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, server_name: str, key_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes the server key with the given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param key_name: The name of the server key to be deleted. + :param key_name: The name of the server key to be deleted. Required. :type key_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -444,53 +487,46 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, key_name=key_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_operations_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_operations_operations.py index e041369c07f68..c04847931bf0e 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_operations_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_operations_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,9 +26,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._server_operations_operations import build_list_by_server_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServerOperationsOperations: """ .. warning:: @@ -42,50 +50,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ServerOperationListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ServerOperation"]: """Gets a list of operations performed on the server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerOperationListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerOperationListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServerOperation or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerOperation] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerOperationListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerOperationListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -93,16 +91,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -118,10 +107,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -131,8 +118,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/operations"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/operations"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_security_alert_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_security_alert_policies_operations.py index c1d83874c411f..6843e2f083726 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_security_alert_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_security_alert_policies_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._server_security_alert_policies_operations import build_create_or_update_request_initial, build_get_request, build_list_by_server_request -T = TypeVar('T') +from ...operations._server_security_alert_policies_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_server_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServerSecurityAlertPoliciesOperations: """ .. warning:: @@ -45,7 +57,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -57,39 +68,33 @@ async def get( """Get a server's security alert policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param security_alert_policy_name: The name of the security alert policy. + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerSecurityAlertPolicy, or the result of cls(response) + :return: ServerSecurityAlertPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerSecurityAlertPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerSecurityAlertPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerSecurityAlertPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, security_alert_policy_name=security_alert_policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,49 +102,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ServerSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], - parameters: _models.ServerSecurityAlertPolicy, + parameters: Union[_models.ServerSecurityAlertPolicy, IO], **kwargs: Any ) -> Optional[_models.ServerSecurityAlertPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerSecurityAlertPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerSecurityAlertPolicy]] - _json = self._serialize.body(parameters, 'ServerSecurityAlertPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerSecurityAlertPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, security_alert_policy_name=security_alert_policy_name, @@ -147,7 +154,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -155,10 +163,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -167,39 +174,117 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ServerSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], parameters: _models.ServerSecurityAlertPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ServerSecurityAlertPolicy]: """Creates or updates a threat detection policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param security_alert_policy_name: The name of the threat detection policy. + :param security_alert_policy_name: The name of the threat detection policy. "Default" Required. :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName - :param parameters: The server security alert policy. + :param parameters: The server security alert policy. Required. :type parameters: ~azure.mgmt.sql.models.ServerSecurityAlertPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ServerSecurityAlertPolicy or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerSecurityAlertPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerSecurityAlertPolicy]: + """Creates or updates a threat detection policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param security_alert_policy_name: The name of the threat detection policy. "Default" Required. + :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName + :param parameters: The server security alert policy. Required. + :type parameters: IO + :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 ServerSecurityAlertPolicy or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerSecurityAlertPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], + parameters: Union[_models.ServerSecurityAlertPolicy, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerSecurityAlertPolicy]: + """Creates or updates a threat detection policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param security_alert_policy_name: The name of the threat detection policy. "Default" Required. + :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName + :param parameters: The server security alert policy. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ServerSecurityAlertPolicy 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 @@ -211,20 +296,17 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either ServerSecurityAlertPolicy or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerSecurityAlertPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerSecurityAlertPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerSecurityAlertPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -233,83 +315,72 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ServerSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.LogicalServerSecurityAlertPolicyListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ServerSecurityAlertPolicy"]: """Get the server's threat detection policies. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LogicalServerSecurityAlertPolicyListResult or the - result of cls(response) + :return: An iterator like instance of either ServerSecurityAlertPolicy or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LogicalServerSecurityAlertPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerSecurityAlertPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LogicalServerSecurityAlertPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LogicalServerSecurityAlertPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -317,16 +388,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -342,10 +404,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -355,8 +415,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_trust_certificates_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_trust_certificates_operations.py index 7c00a6f79eaeb..3ac6bc1f8a5ce 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_trust_certificates_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_trust_certificates_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._server_trust_certificates_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_instance_request -T = TypeVar('T') +from ...operations._server_trust_certificates_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_instance_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServerTrustCertificatesOperations: """ .. warning:: @@ -45,51 +58,42 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ServerTrustCertificatesListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ServerTrustCertificate"]: """Gets a list of server trust certificates that were uploaded from box to the given Sql Managed Instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerTrustCertificatesListResult or the result of + :return: An iterator like instance of either ServerTrustCertificate or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerTrustCertificatesListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerTrustCertificate] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerTrustCertificatesListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerTrustCertificatesListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -97,16 +101,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -122,10 +117,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -135,56 +128,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - managed_instance_name: str, - certificate_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, certificate_name: str, **kwargs: Any ) -> _models.ServerTrustCertificate: """Gets a server trust certificate that was uploaded from box to Sql Managed Instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param certificate_name: Name of of the certificate to get. + :param certificate_name: Name of of the certificate to get. Required. :type certificate_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerTrustCertificate, or the result of cls(response) + :return: ServerTrustCertificate or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerTrustCertificate - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerTrustCertificate] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerTrustCertificate] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, certificate_name=certificate_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -192,49 +173,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerTrustCertificate', pipeline_response) + deserialized = self._deserialize("ServerTrustCertificate", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, certificate_name: str, - parameters: _models.ServerTrustCertificate, + parameters: Union[_models.ServerTrustCertificate, IO], **kwargs: Any ) -> Optional[_models.ServerTrustCertificate]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerTrustCertificate]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerTrustCertificate]] - _json = self._serialize.body(parameters, 'ServerTrustCertificate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerTrustCertificate") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, certificate_name=certificate_name, @@ -242,7 +225,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -250,10 +234,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -262,42 +245,43 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerTrustCertificate', pipeline_response) + deserialized = self._deserialize("ServerTrustCertificate", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ServerTrustCertificate', pipeline_response) + deserialized = self._deserialize("ServerTrustCertificate", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, certificate_name: str, parameters: _models.ServerTrustCertificate, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ServerTrustCertificate]: """Uploads a server trust certificate from box to Sql Managed Instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param certificate_name: Name of of the certificate to upload. + :param certificate_name: Name of of the certificate to upload. Required. :type certificate_name: str - :param parameters: The server trust certificate info. + :param parameters: The server trust certificate info. Required. :type parameters: ~azure.mgmt.sql.models.ServerTrustCertificate - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -309,20 +293,94 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either ServerTrustCertificate or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerTrustCertificate] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + certificate_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerTrustCertificate]: + """Uploads a server trust certificate from box to Sql Managed Instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param certificate_name: Name of of the certificate to upload. Required. + :type certificate_name: str + :param parameters: The server trust certificate info. Required. + :type parameters: IO + :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 ServerTrustCertificate or the result + of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerTrustCertificate] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + certificate_name: str, + parameters: Union[_models.ServerTrustCertificate, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerTrustCertificate]: + """Uploads a server trust certificate from box to Sql Managed Instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param certificate_name: Name of of the certificate to upload. Required. + :type certificate_name: str + :param parameters: The server trust certificate info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ServerTrustCertificate 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. + :return: An instance of AsyncLROPoller that returns either ServerTrustCertificate or the result + of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerTrustCertificate] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerTrustCertificate] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerTrustCertificate] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -331,66 +389,55 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerTrustCertificate', pipeline_response) + deserialized = self._deserialize("ServerTrustCertificate", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - certificate_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, certificate_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, certificate_name=certificate_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -398,10 +445,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -411,29 +457,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - certificate_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, managed_instance_name: str, certificate_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes a server trust certificate that was uploaded from box to Sql Managed Instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param certificate_name: Name of of the certificate to delete. + :param certificate_name: Name of of the certificate to delete. Required. :type certificate_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -444,53 +482,46 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, certificate_name=certificate_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_trust_groups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_trust_groups_operations.py index 3b57cd4b8b178..b8f9e02862f44 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_trust_groups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_trust_groups_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,18 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._server_trust_groups_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_instance_request, build_list_by_location_request -T = TypeVar('T') +from ...operations._server_trust_groups_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_instance_request, + build_list_by_location_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServerTrustGroupsOperations: """ .. warning:: @@ -45,51 +59,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - resource_group_name: str, - location_name: str, - server_trust_group_name: str, - **kwargs: Any + self, resource_group_name: str, location_name: str, server_trust_group_name: str, **kwargs: Any ) -> _models.ServerTrustGroup: """Gets a server trust group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param server_trust_group_name: The name of the server trust group. + :param server_trust_group_name: The name of the server trust group. Required. :type server_trust_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerTrustGroup, or the result of cls(response) + :return: ServerTrustGroup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerTrustGroup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerTrustGroup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerTrustGroup] - request = build_get_request( resource_group_name=resource_group_name, location_name=location_name, server_trust_group_name=server_trust_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,49 +100,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerTrustGroup', pipeline_response) + deserialized = self._deserialize("ServerTrustGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, location_name: str, server_trust_group_name: str, - parameters: _models.ServerTrustGroup, + parameters: Union[_models.ServerTrustGroup, IO], **kwargs: Any ) -> Optional[_models.ServerTrustGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerTrustGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerTrustGroup]] - _json = self._serialize.body(parameters, 'ServerTrustGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerTrustGroup") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, location_name=location_name, server_trust_group_name=server_trust_group_name, @@ -147,7 +152,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -155,10 +161,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -167,42 +172,120 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerTrustGroup', pipeline_response) + deserialized = self._deserialize("ServerTrustGroup", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ServerTrustGroup', pipeline_response) + deserialized = self._deserialize("ServerTrustGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, location_name: str, server_trust_group_name: str, parameters: _models.ServerTrustGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ServerTrustGroup]: """Creates or updates a server trust group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param server_trust_group_name: The name of the server trust group. + :param server_trust_group_name: The name of the server trust group. Required. :type server_trust_group_name: str - :param parameters: The server trust group parameters. + :param parameters: The server trust group parameters. Required. :type parameters: ~azure.mgmt.sql.models.ServerTrustGroup - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ServerTrustGroup or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerTrustGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + location_name: str, + server_trust_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerTrustGroup]: + """Creates or updates a server trust group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param location_name: The name of the region where the resource is located. Required. + :type location_name: str + :param server_trust_group_name: The name of the server trust group. Required. + :type server_trust_group_name: str + :param parameters: The server trust group parameters. Required. + :type parameters: IO + :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 ServerTrustGroup or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerTrustGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + location_name: str, + server_trust_group_name: str, + parameters: Union[_models.ServerTrustGroup, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ServerTrustGroup]: + """Creates or updates a server trust group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param location_name: The name of the region where the resource is located. Required. + :type location_name: str + :param server_trust_group_name: The name of the server trust group. Required. + :type server_trust_group_name: str + :param parameters: The server trust group parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ServerTrustGroup 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 @@ -214,20 +297,17 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either ServerTrustGroup or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ServerTrustGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerTrustGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerTrustGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -236,66 +316,55 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerTrustGroup', pipeline_response) + deserialized = self._deserialize("ServerTrustGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - location_name: str, - server_trust_group_name: str, - **kwargs: Any + self, resource_group_name: str, location_name: str, server_trust_group_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, location_name=location_name, server_trust_group_name=server_trust_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -303,10 +372,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -316,29 +384,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - location_name: str, - server_trust_group_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, location_name: str, server_trust_group_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes a server trust group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param server_trust_group_name: The name of the server trust group. + :param server_trust_group_name: The name of the server trust group. Required. :type server_trust_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -349,100 +409,84 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, location_name=location_name, server_trust_group_name=server_trust_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore @distributed_trace def list_by_location( - self, - resource_group_name: str, - location_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ServerTrustGroupListResult]: + self, resource_group_name: str, location_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ServerTrustGroup"]: """Lists a server trust group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerTrustGroupListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerTrustGroupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServerTrustGroup or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerTrustGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerTrustGroupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerTrustGroupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_location_request( resource_group_name=resource_group_name, location_name=location_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_location.metadata['url'], + template_url=self.list_by_location.metadata["url"], headers=_headers, params=_params, ) @@ -450,16 +494,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_location_request( - resource_group_name=resource_group_name, - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -475,10 +510,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -488,55 +521,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups"} # type: ignore + list_by_location.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups"} # type: ignore @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ServerTrustGroupListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ServerTrustGroup"]: """Gets a server trust groups by instance name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerTrustGroupListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerTrustGroupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServerTrustGroup or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerTrustGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerTrustGroupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerTrustGroupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -544,16 +566,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -569,10 +582,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -582,8 +593,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustGroups"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustGroups"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_usages_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_usages_operations.py index 2049eb7942506..67dbafc8f10b1 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_usages_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_usages_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,9 +26,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._server_usages_operations import build_list_by_server_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServerUsagesOperations: """ .. warning:: @@ -42,49 +50,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ServerUsageListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ServerUsage"]: """Returns server usages. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerUsageListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerUsageListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServerUsage or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerUsage] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerUsageListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerUsageListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -92,16 +91,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -117,10 +107,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -130,8 +118,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/usages"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/usages"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_vulnerability_assessments_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_vulnerability_assessments_operations.py index 0760b6b2b5bcc..c3e45c0c2549b 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_vulnerability_assessments_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_server_vulnerability_assessments_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._server_vulnerability_assessments_operations import build_create_or_update_request, build_delete_request, build_get_request, build_list_by_server_request -T = TypeVar('T') +from ...operations._server_vulnerability_assessments_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_server_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServerVulnerabilityAssessmentsOperations: """ .. warning:: @@ -43,7 +56,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -55,39 +67,35 @@ async def get( """Gets the server's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param server_name: The name of the server for which the vulnerability assessment is defined. + Required. :type server_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerVulnerabilityAssessment, or the result of cls(response) + :return: ServerVulnerabilityAssessment or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerVulnerabilityAssessment - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerVulnerabilityAssessment] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerVulnerabilityAssessment] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -95,33 +103,33 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("ServerVulnerabilityAssessment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, server_name: str, vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], parameters: _models.ServerVulnerabilityAssessment, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.ServerVulnerabilityAssessment: """Creates or updates the server's vulnerability assessment. Learn more about setting SQL @@ -129,35 +137,109 @@ async def create_or_update( https://docs.microsoft.com/azure/azure-sql/database/sql-database-vulnerability-assessment-storage. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param server_name: The name of the server for which the vulnerability assessment is defined. + Required. :type server_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param parameters: The requested resource. + :param parameters: The requested resource. Required. :type parameters: ~azure.mgmt.sql.models.ServerVulnerabilityAssessment - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: ServerVulnerabilityAssessment, or the result of cls(response) + :return: ServerVulnerabilityAssessment or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerVulnerabilityAssessment - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.ServerVulnerabilityAssessment: + """Creates or updates the server's vulnerability assessment. Learn more about setting SQL + vulnerability assessment with managed identity - + https://docs.microsoft.com/azure/azure-sql/database/sql-database-vulnerability-assessment-storage. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server for which the vulnerability assessment is defined. + Required. + :type server_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param parameters: The requested resource. Required. + :type parameters: IO + :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: ServerVulnerabilityAssessment or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ServerVulnerabilityAssessment + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + parameters: Union[_models.ServerVulnerabilityAssessment, IO], + **kwargs: Any + ) -> _models.ServerVulnerabilityAssessment: + """Creates or updates the server's vulnerability assessment. Learn more about setting SQL + vulnerability assessment with managed identity - + https://docs.microsoft.com/azure/azure-sql/database/sql-database-vulnerability-assessment-storage. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server for which the vulnerability assessment is defined. + Required. + :type server_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param parameters: The requested resource. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerVulnerabilityAssessment 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 + :return: ServerVulnerabilityAssessment or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ServerVulnerabilityAssessment + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerVulnerabilityAssessment] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerVulnerabilityAssessment] - _json = self._serialize.body(parameters, 'ServerVulnerabilityAssessment') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerVulnerabilityAssessment") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -167,7 +249,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -175,10 +258,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -186,18 +268,17 @@ async def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('ServerVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("ServerVulnerabilityAssessment", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ServerVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("ServerVulnerabilityAssessment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -210,39 +291,35 @@ async def delete( # pylint: disable=inconsistent-return-statements """Removes the server's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param server_name: The name of the server for which the vulnerability assessment is defined. + Required. :type server_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -250,10 +327,9 @@ async def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -263,52 +339,44 @@ async def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ServerVulnerabilityAssessmentListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ServerVulnerabilityAssessment"]: """Lists the vulnerability assessment policies associated with a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerVulnerabilityAssessmentListResult or the - result of cls(response) + :return: An iterator like instance of either ServerVulnerabilityAssessment or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerVulnerabilityAssessmentListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerVulnerabilityAssessment] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerVulnerabilityAssessmentListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerVulnerabilityAssessmentListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -316,16 +384,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -341,10 +400,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -354,8 +411,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_servers_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_servers_operations.py index ae21ebcb62c52..a9ff927124ede 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_servers_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_servers_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,21 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._servers_operations import build_check_name_availability_request, build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_import_database_request_initial, build_list_by_resource_group_request, build_list_request, build_update_request_initial -T = TypeVar('T') +from ...operations._servers_operations import ( + build_check_name_availability_request, + build_create_or_update_request, + build_delete_request, + build_get_request, + build_import_database_request, + build_list_by_resource_group_request, + build_list_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServersOperations: """ .. warning:: @@ -45,48 +62,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_resource_group( - self, - resource_group_name: str, - expand: Optional[str] = None, - **kwargs: Any - ) -> AsyncIterable[_models.ServerListResult]: + self, resource_group_name: str, expand: Optional[str] = None, **kwargs: Any + ) -> AsyncIterable["_models.Server"]: """Gets a list of servers in a resource groups. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerListResult or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Server or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.Server] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_request( resource_group_name=resource_group_name, subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.list_by_resource_group.metadata['url'], + api_version=api_version, + template_url=self.list_by_resource_group.metadata["url"], headers=_headers, params=_params, ) @@ -94,16 +103,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - expand=expand, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -119,10 +119,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -132,56 +130,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers"} # type: ignore + list_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - expand: Optional[str] = None, - **kwargs: Any + self, resource_group_name: str, server_name: str, expand: Optional[str] = None, **kwargs: Any ) -> _models.Server: """Gets a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Server, or the result of cls(response) + :return: Server or the result of cls(response) :rtype: ~azure.mgmt.sql.models.Server - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.Server] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.Server] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.get.metadata['url'], + api_version=api_version, + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -189,55 +175,54 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('Server', pipeline_response) + deserialized = self._deserialize("Server", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore async def _create_or_update_initial( - self, - resource_group_name: str, - server_name: str, - parameters: _models.Server, - **kwargs: Any + self, resource_group_name: str, server_name: str, parameters: Union[_models.Server, IO], **kwargs: Any ) -> Optional[_models.Server]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.Server]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.Server]] - _json = self._serialize.body(parameters, 'Server') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "Server") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -245,10 +230,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -257,39 +241,40 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Server', pipeline_response) + deserialized = self._deserialize("Server", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('Server', pipeline_response) + deserialized = self._deserialize("Server", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, parameters: _models.Server, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.Server]: """Creates or updates a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param parameters: The requested server resource state. + :param parameters: The requested server resource state. Required. :type parameters: ~azure.mgmt.sql.models.Server - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -301,20 +286,84 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either Server or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.Server] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.Server]: + """Creates or updates a server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The requested server resource state. Required. + :type parameters: IO + :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 Server or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.Server] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, resource_group_name: str, server_name: str, parameters: Union[_models.Server, IO], **kwargs: Any + ) -> AsyncLROPoller[_models.Server]: + """Creates or updates a server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The requested server resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.Server 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. + :return: An instance of AsyncLROPoller that returns either Server or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.Server] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.Server] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.Server] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -322,64 +371,54 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('Server', pipeline_response) + deserialized = self._deserialize("Server", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -387,10 +426,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -400,26 +438,17 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncLROPoller[None]: + async def begin_delete(self, resource_group_name: str, server_name: str, **kwargs: Any) -> AsyncLROPoller[None]: """Deletes a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -430,85 +459,79 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore async def _update_initial( - self, - resource_group_name: str, - server_name: str, - parameters: _models.ServerUpdate, - **kwargs: Any + self, resource_group_name: str, server_name: str, parameters: Union[_models.ServerUpdate, IO], **kwargs: Any ) -> Optional[_models.Server]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.Server]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.Server]] - _json = self._serialize.body(parameters, 'ServerUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -516,10 +539,9 @@ async def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -528,36 +550,73 @@ async def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Server', pipeline_response) + deserialized = self._deserialize("Server", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_update( self, resource_group_name: str, server_name: str, parameters: _models.ServerUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.Server]: """Updates a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param parameters: The requested server resource state. + :param parameters: The requested server resource state. Required. :type parameters: ~azure.mgmt.sql.models.ServerUpdate - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 Server or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.Server] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_update( + self, + resource_group_name: str, + server_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.Server]: + """Updates a server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The requested server resource state. Required. + :type parameters: IO + :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 @@ -569,20 +628,48 @@ async def begin_update( :return: An instance of AsyncLROPoller that returns either Server or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.Server] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_update( + self, resource_group_name: str, server_name: str, parameters: Union[_models.ServerUpdate, IO], **kwargs: Any + ) -> AsyncLROPoller[_models.Server]: + """Updates a server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The requested server resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ServerUpdate 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. + :return: An instance of AsyncLROPoller that returns either Server or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.Server] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.Server] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.Server] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -590,76 +677,64 @@ async def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('Server', pipeline_response) + deserialized = self._deserialize("Server", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore @distributed_trace - def list( - self, - expand: Optional[str] = None, - **kwargs: Any - ) -> AsyncIterable[_models.ServerListResult]: + def list(self, expand: Optional[str] = None, **kwargs: Any) -> AsyncIterable["_models.Server"]: """Gets a list of all servers in the subscription. :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerListResult or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServerListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Server or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.Server] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_request( subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.list.metadata['url'], + api_version=api_version, + template_url=self.list.metadata["url"], headers=_headers, params=_params, ) @@ -667,15 +742,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_request( - subscription_id=self._config.subscription_id, - api_version=api_version, - expand=expand, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -691,10 +758,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -704,41 +769,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/servers"} # type: ignore + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/servers"} # type: ignore async def _import_database_initial( self, resource_group_name: str, server_name: str, - parameters: _models.ImportNewDatabaseDefinition, + parameters: Union[_models.ImportNewDatabaseDefinition, IO], **kwargs: Any ) -> Optional[_models.ImportExportOperationResult]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ImportExportOperationResult]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ImportExportOperationResult]] - _json = self._serialize.body(parameters, 'ImportNewDatabaseDefinition') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ImportNewDatabaseDefinition") - request = build_import_database_request_initial( + request = build_import_database_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._import_database_initial.metadata['url'], + content=_content, + template_url=self._import_database_initial.metadata["url"], headers=_headers, params=_params, ) @@ -746,10 +814,9 @@ async def _import_database_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -758,36 +825,37 @@ async def _import_database_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ImportExportOperationResult', pipeline_response) + deserialized = self._deserialize("ImportExportOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _import_database_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/import"} # type: ignore + _import_database_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/import"} # type: ignore - - @distributed_trace_async + @overload async def begin_import_database( self, resource_group_name: str, server_name: str, parameters: _models.ImportNewDatabaseDefinition, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.ImportExportOperationResult]: """Imports a bacpac into a new database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param parameters: The database import request parameters. + :param parameters: The database import request parameters. Required. :type parameters: ~azure.mgmt.sql.models.ImportNewDatabaseDefinition - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -799,20 +867,88 @@ async def begin_import_database( :return: An instance of AsyncLROPoller that returns either ImportExportOperationResult or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_import_database( + self, + resource_group_name: str, + server_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.ImportExportOperationResult]: + """Imports a bacpac into a new database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The database import request parameters. Required. + :type parameters: IO + :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 ImportExportOperationResult or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_import_database( + self, + resource_group_name: str, + server_name: str, + parameters: Union[_models.ImportNewDatabaseDefinition, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.ImportExportOperationResult]: + """Imports a bacpac into a new database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The database import request parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ImportNewDatabaseDefinition 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. + :return: An instance of AsyncLROPoller that returns either ImportExportOperationResult or the + result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ImportExportOperationResult] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ImportExportOperationResult] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._import_database_initial( # type: ignore resource_group_name=resource_group_name, @@ -820,78 +956,112 @@ async def begin_import_database( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ImportExportOperationResult', pipeline_response) + deserialized = self._deserialize("ImportExportOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_import_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/import"} # type: ignore + begin_import_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/import"} # type: ignore - @distributed_trace_async + @overload async def check_name_availability( - self, - parameters: _models.CheckNameAvailabilityRequest, - **kwargs: Any + self, parameters: _models.CheckNameAvailabilityRequest, *, content_type: str = "application/json", **kwargs: Any ) -> _models.CheckNameAvailabilityResponse: """Determines whether a resource can be created with the specified name. - :param parameters: The name availability request parameters. + :param parameters: The name availability request parameters. Required. :type parameters: ~azure.mgmt.sql.models.CheckNameAvailabilityRequest - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: CheckNameAvailabilityResponse or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.CheckNameAvailabilityResponse + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def check_name_availability( + self, parameters: IO, *, content_type: str = "application/json", **kwargs: Any + ) -> _models.CheckNameAvailabilityResponse: + """Determines whether a resource can be created with the specified name. + + :param parameters: The name availability request parameters. Required. + :type parameters: IO + :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: CheckNameAvailabilityResponse, or the result of cls(response) + :return: CheckNameAvailabilityResponse or the result of cls(response) :rtype: ~azure.mgmt.sql.models.CheckNameAvailabilityResponse - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace_async + async def check_name_availability( + self, parameters: Union[_models.CheckNameAvailabilityRequest, IO], **kwargs: Any + ) -> _models.CheckNameAvailabilityResponse: + """Determines whether a resource can be created with the specified name. + + :param parameters: The name availability request parameters. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.CheckNameAvailabilityRequest 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 + :return: CheckNameAvailabilityResponse or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.CheckNameAvailabilityResponse + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.CheckNameAvailabilityResponse] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.CheckNameAvailabilityResponse] - _json = self._serialize.body(parameters, 'CheckNameAvailabilityRequest') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "CheckNameAvailabilityRequest") request = build_check_name_availability_request( subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self.check_name_availability.metadata['url'], + content=_content, + template_url=self.check_name_availability.metadata["url"], headers=_headers, params=_params, ) @@ -899,22 +1069,20 @@ async def check_name_availability( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('CheckNameAvailabilityResponse', pipeline_response) + deserialized = self._deserialize("CheckNameAvailabilityResponse", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - check_name_availability.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/checkNameAvailability"} # type: ignore - + check_name_availability.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/checkNameAvailability"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_service_objectives_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_service_objectives_operations.py index fefe7a211d670..1afa4c52ddebf 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_service_objectives_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_service_objectives_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._service_objectives_operations import build_get_request, build_list_by_server_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class ServiceObjectivesOperations: """ .. warning:: @@ -43,51 +51,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - service_objective_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, service_objective_name: str, **kwargs: Any ) -> _models.ServiceObjective: """Gets a database service objective. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param service_objective_name: The name of the service objective to retrieve. + :param service_objective_name: The name of the service objective to retrieve. Required. :type service_objective_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServiceObjective, or the result of cls(response) + :return: ServiceObjective or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServiceObjective - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServiceObjective] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceObjective] - request = build_get_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, service_objective_name=service_objective_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -95,69 +92,58 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServiceObjective', pipeline_response) + deserialized = self._deserialize("ServiceObjective", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/serviceObjectives/{serviceObjectiveName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/serviceObjectives/{serviceObjectiveName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.ServiceObjectiveListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.ServiceObjective"]: """Returns database service objectives. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServiceObjectiveListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServiceObjectiveListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServiceObjective or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.ServiceObjective] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServiceObjectiveListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceObjectiveListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -165,16 +151,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -190,10 +167,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -203,8 +178,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/serviceObjectives"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/serviceObjectives"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sql_agent_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sql_agent_operations.py index c0521b4567f26..1a5b1124a51a6 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sql_agent_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sql_agent_operations.py @@ -6,9 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -19,9 +25,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._sql_agent_operations import build_create_or_update_request, build_get_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class SqlAgentOperations: """ .. warning:: @@ -41,47 +49,37 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any ) -> _models.SqlAgentConfiguration: """Gets current instance sql agent configuration. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SqlAgentConfiguration, or the result of cls(response) + :return: SqlAgentConfiguration or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SqlAgentConfiguration - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SqlAgentConfiguration] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SqlAgentConfiguration] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -89,64 +87,122 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SqlAgentConfiguration', pipeline_response) + deserialized = self._deserialize("SqlAgentConfiguration", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/sqlAgent/current"} # type: ignore + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/sqlAgent/current"} # type: ignore - - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, managed_instance_name: str, parameters: _models.SqlAgentConfiguration, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.SqlAgentConfiguration: """Puts new sql agent configuration to instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.SqlAgentConfiguration - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: SqlAgentConfiguration or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.SqlAgentConfiguration + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.SqlAgentConfiguration: + """Puts new sql agent configuration to instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param parameters: Required. + :type parameters: IO + :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: SqlAgentConfiguration or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.SqlAgentConfiguration + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + parameters: Union[_models.SqlAgentConfiguration, IO], + **kwargs: Any + ) -> _models.SqlAgentConfiguration: + """Puts new sql agent configuration to instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.SqlAgentConfiguration 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 - :return: SqlAgentConfiguration, or the result of cls(response) + :return: SqlAgentConfiguration or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SqlAgentConfiguration - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.SqlAgentConfiguration] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.SqlAgentConfiguration] - _json = self._serialize.body(parameters, 'SqlAgentConfiguration') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SqlAgentConfiguration") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -155,7 +211,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -163,22 +220,20 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SqlAgentConfiguration', pipeline_response) + deserialized = self._deserialize("SqlAgentConfiguration", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/sqlAgent/current"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/sqlAgent/current"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_subscription_usages_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_subscription_usages_operations.py index d4dd12aedb370..77dfc5ebf91c5 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_subscription_usages_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_subscription_usages_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._subscription_usages_operations import build_get_request, build_list_by_location_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class SubscriptionUsagesOperations: """ .. warning:: @@ -43,45 +51,34 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace - def list_by_location( - self, - location_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.SubscriptionUsageListResult]: + def list_by_location(self, location_name: str, **kwargs: Any) -> AsyncIterable["_models.SubscriptionUsage"]: """Gets all subscription usage metrics in a given location. - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SubscriptionUsageListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SubscriptionUsageListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SubscriptionUsage or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SubscriptionUsage] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SubscriptionUsageListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SubscriptionUsageListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_location_request( location_name=location_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_location.metadata['url'], + template_url=self.list_by_location.metadata["url"], headers=_headers, params=_params, ) @@ -89,15 +86,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_location_request( - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -113,10 +102,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -126,51 +113,38 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/usages"} # type: ignore + list_by_location.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/usages"} # type: ignore @distributed_trace_async - async def get( - self, - location_name: str, - usage_name: str, - **kwargs: Any - ) -> _models.SubscriptionUsage: + async def get(self, location_name: str, usage_name: str, **kwargs: Any) -> _models.SubscriptionUsage: """Gets a subscription usage metric. - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param usage_name: Name of usage metric to return. + :param usage_name: Name of usage metric to return. Required. :type usage_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SubscriptionUsage, or the result of cls(response) + :return: SubscriptionUsage or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SubscriptionUsage - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SubscriptionUsage] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SubscriptionUsage] - request = build_get_request( location_name=location_name, usage_name=usage_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -178,22 +152,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SubscriptionUsage', pipeline_response) + deserialized = self._deserialize("SubscriptionUsage", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/usages/{usageName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/usages/{usageName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sync_agents_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sync_agents_operations.py index 1f2737215d1f0..85311ec5d14a8 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sync_agents_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sync_agents_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,19 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._sync_agents_operations import build_create_or_update_request_initial, build_delete_request_initial, build_generate_key_request, build_get_request, build_list_by_server_request, build_list_linked_databases_request -T = TypeVar('T') +from ...operations._sync_agents_operations import ( + build_create_or_update_request, + build_delete_request, + build_generate_key_request, + build_get_request, + build_list_by_server_request, + build_list_linked_databases_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class SyncAgentsOperations: """ .. warning:: @@ -45,51 +60,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - sync_agent_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, sync_agent_name: str, **kwargs: Any ) -> _models.SyncAgent: """Gets a sync agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server on which the sync agent is hosted. + :param server_name: The name of the server on which the sync agent is hosted. Required. :type server_name: str - :param sync_agent_name: The name of the sync agent. + :param sync_agent_name: The name of the sync agent. Required. :type sync_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SyncAgent, or the result of cls(response) + :return: SyncAgent or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SyncAgent - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncAgent] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncAgent] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, sync_agent_name=sync_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,49 +101,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SyncAgent', pipeline_response) + deserialized = self._deserialize("SyncAgent", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, sync_agent_name: str, - parameters: _models.SyncAgent, + parameters: Union[_models.SyncAgent, IO], **kwargs: Any ) -> Optional[_models.SyncAgent]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.SyncAgent]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.SyncAgent]] - _json = self._serialize.body(parameters, 'SyncAgent') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SyncAgent") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, sync_agent_name=sync_agent_name, @@ -147,7 +153,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -155,10 +162,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -167,42 +173,120 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('SyncAgent', pipeline_response) + deserialized = self._deserialize("SyncAgent", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('SyncAgent', pipeline_response) + deserialized = self._deserialize("SyncAgent", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, sync_agent_name: str, parameters: _models.SyncAgent, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.SyncAgent]: """Creates or updates a sync agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server on which the sync agent is hosted. + :param server_name: The name of the server on which the sync agent is hosted. Required. :type server_name: str - :param sync_agent_name: The name of the sync agent. + :param sync_agent_name: The name of the sync agent. Required. :type sync_agent_name: str - :param parameters: The requested sync agent resource state. + :param parameters: The requested sync agent resource state. Required. :type parameters: ~azure.mgmt.sql.models.SyncAgent - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 SyncAgent or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.SyncAgent] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + sync_agent_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.SyncAgent]: + """Creates or updates a sync agent. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server on which the sync agent is hosted. Required. + :type server_name: str + :param sync_agent_name: The name of the sync agent. Required. + :type sync_agent_name: str + :param parameters: The requested sync agent resource state. Required. + :type parameters: IO + :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 SyncAgent or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.SyncAgent] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + sync_agent_name: str, + parameters: Union[_models.SyncAgent, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.SyncAgent]: + """Creates or updates a sync agent. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server on which the sync agent is hosted. Required. + :type server_name: str + :param sync_agent_name: The name of the sync agent. Required. + :type sync_agent_name: str + :param parameters: The requested sync agent resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.SyncAgent 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 @@ -214,20 +298,17 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either SyncAgent or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.SyncAgent] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncAgent] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncAgent] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -236,66 +317,55 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('SyncAgent', pipeline_response) + deserialized = self._deserialize("SyncAgent", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - sync_agent_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, sync_agent_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, sync_agent_name=sync_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -303,10 +373,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -316,29 +385,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - sync_agent_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, server_name: str, sync_agent_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes a sync agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server on which the sync agent is hosted. + :param server_name: The name of the server on which the sync agent is hosted. Required. :type server_name: str - :param sync_agent_name: The name of the sync agent. + :param sync_agent_name: The name of the sync agent. Required. :type sync_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -349,98 +410,84 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, sync_agent_name=sync_agent_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.SyncAgentListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.SyncAgent"]: """Lists sync agents in a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server on which the sync agent is hosted. + :param server_name: The name of the server on which the sync agent is hosted. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SyncAgentListResult or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SyncAgentListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SyncAgent or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SyncAgent] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncAgentListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncAgentListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -448,16 +495,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -473,10 +511,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -486,56 +522,44 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents"} # type: ignore @distributed_trace_async async def generate_key( - self, - resource_group_name: str, - server_name: str, - sync_agent_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, sync_agent_name: str, **kwargs: Any ) -> _models.SyncAgentKeyProperties: """Generates a sync agent key. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server on which the sync agent is hosted. + :param server_name: The name of the server on which the sync agent is hosted. Required. :type server_name: str - :param sync_agent_name: The name of the sync agent. + :param sync_agent_name: The name of the sync agent. Required. :type sync_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SyncAgentKeyProperties, or the result of cls(response) + :return: SyncAgentKeyProperties or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SyncAgentKeyProperties - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncAgentKeyProperties] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncAgentKeyProperties] - request = build_generate_key_request( resource_group_name=resource_group_name, server_name=server_name, sync_agent_name=sync_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.generate_key.metadata['url'], + template_url=self.generate_key.metadata["url"], headers=_headers, params=_params, ) @@ -543,73 +567,62 @@ async def generate_key( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SyncAgentKeyProperties', pipeline_response) + deserialized = self._deserialize("SyncAgentKeyProperties", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - generate_key.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}/generateKey"} # type: ignore - + generate_key.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}/generateKey"} # type: ignore @distributed_trace def list_linked_databases( - self, - resource_group_name: str, - server_name: str, - sync_agent_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.SyncAgentLinkedDatabaseListResult]: + self, resource_group_name: str, server_name: str, sync_agent_name: str, **kwargs: Any + ) -> AsyncIterable["_models.SyncAgentLinkedDatabase"]: """Lists databases linked to a sync agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server on which the sync agent is hosted. + :param server_name: The name of the server on which the sync agent is hosted. Required. :type server_name: str - :param sync_agent_name: The name of the sync agent. + :param sync_agent_name: The name of the sync agent. Required. :type sync_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SyncAgentLinkedDatabaseListResult or the result of + :return: An iterator like instance of either SyncAgentLinkedDatabase or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SyncAgentLinkedDatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SyncAgentLinkedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncAgentLinkedDatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncAgentLinkedDatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_linked_databases_request( resource_group_name=resource_group_name, server_name=server_name, sync_agent_name=sync_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_linked_databases.metadata['url'], + template_url=self.list_linked_databases.metadata["url"], headers=_headers, params=_params, ) @@ -617,17 +630,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_linked_databases_request( - resource_group_name=resource_group_name, - server_name=server_name, - sync_agent_name=sync_agent_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -643,10 +646,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -656,8 +657,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_linked_databases.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}/linkedDatabases"} # type: ignore + list_linked_databases.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}/linkedDatabases"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sync_groups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sync_groups_operations.py index 459b2d11866d1..c469f04671a2c 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sync_groups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sync_groups_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,24 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._sync_groups_operations import build_cancel_sync_request, build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_database_request, build_list_hub_schemas_request, build_list_logs_request, build_list_sync_database_ids_request, build_refresh_hub_schema_request_initial, build_trigger_sync_request, build_update_request_initial -T = TypeVar('T') +from ...operations._sync_groups_operations import ( + build_cancel_sync_request, + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_database_request, + build_list_hub_schemas_request, + build_list_logs_request, + build_list_sync_database_ids_request, + build_refresh_hub_schema_request, + build_trigger_sync_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class SyncGroupsOperations: """ .. warning:: @@ -45,45 +65,38 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_sync_database_ids( - self, - location_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.SyncDatabaseIdListResult]: + self, location_name: str, **kwargs: Any + ) -> AsyncIterable["_models.SyncDatabaseIdProperties"]: """Gets a collection of sync database ids. - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SyncDatabaseIdListResult or the result of + :return: An iterator like instance of either SyncDatabaseIdProperties or the result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SyncDatabaseIdListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SyncDatabaseIdProperties] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncDatabaseIdListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncDatabaseIdListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_sync_database_ids_request( location_name=location_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_sync_database_ids.metadata['url'], + template_url=self.list_sync_database_ids.metadata["url"], headers=_headers, params=_params, ) @@ -91,15 +104,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_sync_database_ids_request( - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -115,10 +120,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -128,40 +131,30 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_sync_database_ids.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/syncDatabaseIds"} # type: ignore + list_sync_database_ids.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/syncDatabaseIds"} # type: ignore async def _refresh_hub_schema_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_refresh_hub_schema_request_initial( + request = build_refresh_hub_schema_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, sync_group_name=sync_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._refresh_hub_schema_initial.metadata['url'], + template_url=self._refresh_hub_schema_initial.metadata["url"], headers=_headers, params=_params, ) @@ -169,10 +162,9 @@ async def _refresh_hub_schema_initial( # pylint: disable=inconsistent-return-st request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -182,32 +174,23 @@ async def _refresh_hub_schema_initial( # pylint: disable=inconsistent-return-st if cls: return cls(pipeline_response, None, {}) - _refresh_hub_schema_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/refreshHubSchema"} # type: ignore - + _refresh_hub_schema_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/refreshHubSchema"} # type: ignore @distributed_trace_async - async def begin_refresh_hub_schema( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any + async def begin_refresh_hub_schema( + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Refreshes a hub database schema. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -218,19 +201,16 @@ async def begin_refresh_hub_schema( # pylint: disable=inconsistent-return-state 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._refresh_hub_schema_initial( # type: ignore resource_group_name=resource_group_name, @@ -238,81 +218,68 @@ async def begin_refresh_hub_schema( # pylint: disable=inconsistent-return-state database_name=database_name, sync_group_name=sync_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_refresh_hub_schema.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/refreshHubSchema"} # type: ignore + begin_refresh_hub_schema.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/refreshHubSchema"} # type: ignore @distributed_trace def list_hub_schemas( - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.SyncFullSchemaPropertiesListResult]: + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any + ) -> AsyncIterable["_models.SyncFullSchemaProperties"]: """Gets a collection of hub database schemas. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SyncFullSchemaPropertiesListResult or the result - of cls(response) + :return: An iterator like instance of either SyncFullSchemaProperties or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SyncFullSchemaPropertiesListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SyncFullSchemaProperties] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncFullSchemaPropertiesListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncFullSchemaPropertiesListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_hub_schemas_request( resource_group_name=resource_group_name, server_name=server_name, @@ -320,7 +287,7 @@ def prepare_request(next_link=None): sync_group_name=sync_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_hub_schemas.metadata['url'], + template_url=self.list_hub_schemas.metadata["url"], headers=_headers, params=_params, ) @@ -328,18 +295,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_hub_schemas_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - sync_group_name=sync_group_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -355,10 +311,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -368,11 +322,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_hub_schemas.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/hubSchemas"} # type: ignore + list_hub_schemas.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/hubSchemas"} # type: ignore @distributed_trace def list_logs( @@ -386,61 +338,58 @@ def list_logs( type: Union[str, "_models.SyncGroupsType"], continuation_token_parameter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable[_models.SyncGroupLogListResult]: + ) -> AsyncIterable["_models.SyncGroupLogProperties"]: """Gets a collection of sync group logs. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :param start_time: Get logs generated after this time. + :param start_time: Get logs generated after this time. Required. :type start_time: str - :param end_time: Get logs generated before this time. + :param end_time: Get logs generated before this time. Required. :type end_time: str - :param type: The types of logs to retrieve. + :param type: The types of logs to retrieve. Known values are: "All", "Error", "Warning", and + "Success". Required. :type type: str or ~azure.mgmt.sql.models.SyncGroupsType :param continuation_token_parameter: The continuation token for this operation. Default value is None. :type continuation_token_parameter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SyncGroupLogListResult or the result of + :return: An iterator like instance of either SyncGroupLogProperties or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SyncGroupLogListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SyncGroupLogProperties] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncGroupLogListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncGroupLogListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_logs_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, sync_group_name=sync_group_name, subscription_id=self._config.subscription_id, - api_version=api_version, start_time=start_time, end_time=end_time, type=type, continuation_token_parameter=continuation_token_parameter, - template_url=self.list_logs.metadata['url'], + api_version=api_version, + template_url=self.list_logs.metadata["url"], headers=_headers, params=_params, ) @@ -448,22 +397,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_logs_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - sync_group_name=sync_group_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - start_time=start_time, - end_time=end_time, - type=type, - continuation_token_parameter=continuation_token_parameter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -479,10 +413,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -492,52 +424,39 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_logs.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/logs"} # type: ignore + list_logs.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/logs"} # type: ignore @distributed_trace_async async def cancel_sync( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any ) -> None: """Cancels a sync group synchronization. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_cancel_sync_request( resource_group_name=resource_group_name, server_name=server_name, @@ -545,7 +464,7 @@ async def cancel_sync( # pylint: disable=inconsistent-return-statements sync_group_name=sync_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.cancel_sync.metadata['url'], + template_url=self.cancel_sync.metadata["url"], headers=_headers, params=_params, ) @@ -553,10 +472,9 @@ async def cancel_sync( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -566,49 +484,37 @@ async def cancel_sync( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - cancel_sync.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/cancelSync"} # type: ignore - + cancel_sync.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/cancelSync"} # type: ignore @distributed_trace_async async def trigger_sync( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any ) -> None: """Triggers a sync group synchronization. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_trigger_sync_request( resource_group_name=resource_group_name, server_name=server_name, @@ -616,7 +522,7 @@ async def trigger_sync( # pylint: disable=inconsistent-return-statements sync_group_name=sync_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.trigger_sync.metadata['url'], + template_url=self.trigger_sync.metadata["url"], headers=_headers, params=_params, ) @@ -624,10 +530,9 @@ async def trigger_sync( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -637,49 +542,37 @@ async def trigger_sync( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - trigger_sync.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/triggerSync"} # type: ignore - + trigger_sync.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/triggerSync"} # type: ignore @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any ) -> _models.SyncGroup: """Gets a sync group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SyncGroup, or the result of cls(response) + :return: SyncGroup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SyncGroup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncGroup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncGroup] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -687,7 +580,7 @@ async def get( sync_group_name=sync_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -695,25 +588,23 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SyncGroup', pipeline_response) + deserialized = self._deserialize("SyncGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore async def _create_or_update_initial( self, @@ -721,24 +612,28 @@ async def _create_or_update_initial( server_name: str, database_name: str, sync_group_name: str, - parameters: _models.SyncGroup, + parameters: Union[_models.SyncGroup, IO], **kwargs: Any ) -> Optional[_models.SyncGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.SyncGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.SyncGroup]] - _json = self._serialize.body(parameters, 'SyncGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SyncGroup") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -747,7 +642,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -755,10 +651,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -767,20 +662,19 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('SyncGroup', pipeline_response) + deserialized = self._deserialize("SyncGroup", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('SyncGroup', pipeline_response) + deserialized = self._deserialize("SyncGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, @@ -788,24 +682,109 @@ async def begin_create_or_update( database_name: str, sync_group_name: str, parameters: _models.SyncGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.SyncGroup]: """Creates or updates a sync group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :param parameters: The requested sync group resource state. + :param parameters: The requested sync group resource state. Required. :type parameters: ~azure.mgmt.sql.models.SyncGroup - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 SyncGroup or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.SyncGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + sync_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.SyncGroup]: + """Creates or updates a sync group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database on which the sync group is hosted. Required. + :type database_name: str + :param sync_group_name: The name of the sync group. Required. + :type sync_group_name: str + :param parameters: The requested sync group resource state. Required. + :type parameters: IO + :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 SyncGroup or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.SyncGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + sync_group_name: str, + parameters: Union[_models.SyncGroup, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.SyncGroup]: + """Creates or updates a sync group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database on which the sync group is hosted. Required. + :type database_name: str + :param sync_group_name: The name of the sync group. Required. + :type sync_group_name: str + :param parameters: The requested sync group resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.SyncGroup 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 @@ -817,20 +796,17 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either SyncGroup or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.SyncGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -840,68 +816,56 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('SyncGroup', pipeline_response) + deserialized = self._deserialize("SyncGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, sync_group_name=sync_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -909,10 +873,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -922,32 +885,23 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes a sync group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -958,19 +912,16 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, @@ -978,37 +929,33 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements database_name=database_name, sync_group_name=sync_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore async def _update_initial( self, @@ -1016,24 +963,28 @@ async def _update_initial( server_name: str, database_name: str, sync_group_name: str, - parameters: _models.SyncGroup, + parameters: Union[_models.SyncGroup, IO], **kwargs: Any ) -> Optional[_models.SyncGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.SyncGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.SyncGroup]] - _json = self._serialize.body(parameters, 'SyncGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SyncGroup") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -1042,7 +993,8 @@ async def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1050,10 +1002,9 @@ async def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1062,17 +1013,16 @@ async def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('SyncGroup', pipeline_response) + deserialized = self._deserialize("SyncGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore - + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore - @distributed_trace_async + @overload async def begin_update( self, resource_group_name: str, @@ -1080,24 +1030,26 @@ async def begin_update( database_name: str, sync_group_name: str, parameters: _models.SyncGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.SyncGroup]: """Updates a sync group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :param parameters: The requested sync group resource state. + :param parameters: The requested sync group resource state. Required. :type parameters: ~azure.mgmt.sql.models.SyncGroup - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -1109,20 +1061,100 @@ async def begin_update( :return: An instance of AsyncLROPoller that returns either SyncGroup or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.SyncGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + sync_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.SyncGroup]: + """Updates a sync group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database on which the sync group is hosted. Required. + :type database_name: str + :param sync_group_name: The name of the sync group. Required. + :type sync_group_name: str + :param parameters: The requested sync group resource state. Required. + :type parameters: IO + :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 SyncGroup or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.SyncGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + sync_group_name: str, + parameters: Union[_models.SyncGroup, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.SyncGroup]: + """Updates a sync group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database on which the sync group is hosted. Required. + :type database_name: str + :param sync_group_name: The name of the sync group. Required. + :type sync_group_name: str + :param parameters: The requested sync group resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.SyncGroup 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. + :return: An instance of AsyncLROPoller that returns either SyncGroup or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.SyncGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -1132,85 +1164,73 @@ async def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('SyncGroup', pipeline_response) + deserialized = self._deserialize("SyncGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.SyncGroupListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.SyncGroup"]: """Lists sync groups under a hub database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SyncGroupListResult or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SyncGroupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SyncGroup or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SyncGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncGroupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncGroupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -1218,17 +1238,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1244,10 +1254,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1257,8 +1265,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sync_members_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sync_members_operations.py index d05f676576183..fc554cc0f5a2d 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sync_members_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_sync_members_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,20 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._sync_members_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_sync_group_request, build_list_member_schemas_request, build_refresh_member_schema_request_initial, build_update_request_initial -T = TypeVar('T') +from ...operations._sync_members_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_sync_group_request, + build_list_member_schemas_request, + build_refresh_member_schema_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class SyncMembersOperations: """ .. warning:: @@ -45,7 +61,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -59,36 +74,31 @@ async def get( """Gets a sync member. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. :type sync_group_name: str - :param sync_member_name: The name of the sync member. + :param sync_member_name: The name of the sync member. Required. :type sync_member_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SyncMember, or the result of cls(response) + :return: SyncMember or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SyncMember - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncMember] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncMember] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -97,7 +107,7 @@ async def get( sync_member_name=sync_member_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -105,25 +115,23 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SyncMember', pipeline_response) + deserialized = self._deserialize("SyncMember", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore async def _create_or_update_initial( self, @@ -132,24 +140,28 @@ async def _create_or_update_initial( database_name: str, sync_group_name: str, sync_member_name: str, - parameters: _models.SyncMember, + parameters: Union[_models.SyncMember, IO], **kwargs: Any ) -> Optional[_models.SyncMember]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.SyncMember]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.SyncMember]] - _json = self._serialize.body(parameters, 'SyncMember') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SyncMember") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -159,7 +171,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -167,10 +180,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -179,20 +191,19 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('SyncMember', pipeline_response) + deserialized = self._deserialize("SyncMember", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('SyncMember', pipeline_response) + deserialized = self._deserialize("SyncMember", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, @@ -201,26 +212,29 @@ async def begin_create_or_update( sync_group_name: str, sync_member_name: str, parameters: _models.SyncMember, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.SyncMember]: """Creates or updates a sync member. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. :type sync_group_name: str - :param sync_member_name: The name of the sync member. + :param sync_member_name: The name of the sync member. Required. :type sync_member_name: str - :param parameters: The requested sync member resource state. + :param parameters: The requested sync member resource state. Required. :type parameters: ~azure.mgmt.sql.models.SyncMember - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -232,20 +246,108 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either SyncMember or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.SyncMember] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + sync_group_name: str, + sync_member_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.SyncMember]: + """Creates or updates a sync member. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database on which the sync group is hosted. Required. + :type database_name: str + :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. + :type sync_group_name: str + :param sync_member_name: The name of the sync member. Required. + :type sync_member_name: str + :param parameters: The requested sync member resource state. Required. + :type parameters: IO + :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 SyncMember or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.SyncMember] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + sync_group_name: str, + sync_member_name: str, + parameters: Union[_models.SyncMember, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.SyncMember]: + """Creates or updates a sync member. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database on which the sync group is hosted. Required. + :type database_name: str + :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. + :type sync_group_name: str + :param sync_member_name: The name of the sync member. Required. + :type sync_member_name: str + :param parameters: The requested sync member resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.SyncMember 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. + :return: An instance of AsyncLROPoller that returns either SyncMember or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.SyncMember] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncMember] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncMember] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -256,39 +358,35 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('SyncMember', pipeline_response) + deserialized = self._deserialize("SyncMember", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements self, @@ -299,19 +397,16 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements sync_member_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -319,7 +414,7 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements sync_member_name=sync_member_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -327,10 +422,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -340,11 +434,10 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements + async def begin_delete( self, resource_group_name: str, server_name: str, @@ -356,19 +449,17 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements """Deletes a sync member. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. :type sync_group_name: str - :param sync_member_name: The name of the sync member. + :param sync_member_name: The name of the sync member. Required. :type sync_member_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -379,19 +470,16 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, @@ -400,37 +488,33 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements sync_group_name=sync_group_name, sync_member_name=sync_member_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore async def _update_initial( self, @@ -439,24 +523,28 @@ async def _update_initial( database_name: str, sync_group_name: str, sync_member_name: str, - parameters: _models.SyncMember, + parameters: Union[_models.SyncMember, IO], **kwargs: Any ) -> Optional[_models.SyncMember]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.SyncMember]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.SyncMember]] - _json = self._serialize.body(parameters, 'SyncMember') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SyncMember") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -466,7 +554,8 @@ async def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -474,10 +563,9 @@ async def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -486,17 +574,16 @@ async def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('SyncMember', pipeline_response) + deserialized = self._deserialize("SyncMember", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_update( self, resource_group_name: str, @@ -505,26 +592,29 @@ async def begin_update( sync_group_name: str, sync_member_name: str, parameters: _models.SyncMember, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.SyncMember]: """Updates an existing sync member. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. :type sync_group_name: str - :param sync_member_name: The name of the sync member. + :param sync_member_name: The name of the sync member. Required. :type sync_member_name: str - :param parameters: The requested sync member resource state. + :param parameters: The requested sync member resource state. Required. :type parameters: ~azure.mgmt.sql.models.SyncMember - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -536,20 +626,108 @@ async def begin_update( :return: An instance of AsyncLROPoller that returns either SyncMember or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.SyncMember] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + sync_group_name: str, + sync_member_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.SyncMember]: + """Updates an existing sync member. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database on which the sync group is hosted. Required. + :type database_name: str + :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. + :type sync_group_name: str + :param sync_member_name: The name of the sync member. Required. + :type sync_member_name: str + :param parameters: The requested sync member resource state. Required. + :type parameters: IO + :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 SyncMember or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.SyncMember] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + sync_group_name: str, + sync_member_name: str, + parameters: Union[_models.SyncMember, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.SyncMember]: + """Updates an existing sync member. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database on which the sync group is hosted. Required. + :type database_name: str + :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. + :type sync_group_name: str + :param sync_member_name: The name of the sync member. Required. + :type sync_member_name: str + :param parameters: The requested sync member resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.SyncMember 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. + :return: An instance of AsyncLROPoller that returns either SyncMember or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.SyncMember] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncMember] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncMember] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -560,82 +738,68 @@ async def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('SyncMember', pipeline_response) + deserialized = self._deserialize("SyncMember", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore @distributed_trace def list_by_sync_group( - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.SyncMemberListResult]: + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any + ) -> AsyncIterable["_models.SyncMember"]: """Lists sync members in the given sync group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SyncMemberListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SyncMemberListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SyncMember or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SyncMember] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncMemberListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncMemberListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_sync_group_request( resource_group_name=resource_group_name, server_name=server_name, @@ -643,7 +807,7 @@ def prepare_request(next_link=None): sync_group_name=sync_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_sync_group.metadata['url'], + template_url=self.list_by_sync_group.metadata["url"], headers=_headers, params=_params, ) @@ -651,18 +815,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_sync_group_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - sync_group_name=sync_group_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -678,10 +831,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -691,11 +842,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_sync_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers"} # type: ignore + list_by_sync_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers"} # type: ignore @distributed_trace def list_member_schemas( @@ -706,43 +855,40 @@ def list_member_schemas( sync_group_name: str, sync_member_name: str, **kwargs: Any - ) -> AsyncIterable[_models.SyncFullSchemaPropertiesListResult]: + ) -> AsyncIterable["_models.SyncFullSchemaProperties"]: """Gets a sync member database schema. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. :type sync_group_name: str - :param sync_member_name: The name of the sync member. + :param sync_member_name: The name of the sync member. Required. :type sync_member_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SyncFullSchemaPropertiesListResult or the result - of cls(response) + :return: An iterator like instance of either SyncFullSchemaProperties or the result of + cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SyncFullSchemaPropertiesListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.SyncFullSchemaProperties] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncFullSchemaPropertiesListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncFullSchemaPropertiesListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_member_schemas_request( resource_group_name=resource_group_name, server_name=server_name, @@ -751,7 +897,7 @@ def prepare_request(next_link=None): sync_member_name=sync_member_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_member_schemas.metadata['url'], + template_url=self.list_member_schemas.metadata["url"], headers=_headers, params=_params, ) @@ -759,19 +905,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_member_schemas_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - sync_group_name=sync_group_name, - sync_member_name=sync_member_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -787,10 +921,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -800,11 +932,9 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_member_schemas.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}/schemas"} # type: ignore + list_member_schemas.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}/schemas"} # type: ignore async def _refresh_member_schema_initial( # pylint: disable=inconsistent-return-statements self, @@ -815,19 +945,16 @@ async def _refresh_member_schema_initial( # pylint: disable=inconsistent-return sync_member_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_refresh_member_schema_request_initial( + request = build_refresh_member_schema_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -835,7 +962,7 @@ async def _refresh_member_schema_initial( # pylint: disable=inconsistent-return sync_member_name=sync_member_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._refresh_member_schema_initial.metadata['url'], + template_url=self._refresh_member_schema_initial.metadata["url"], headers=_headers, params=_params, ) @@ -843,10 +970,9 @@ async def _refresh_member_schema_initial( # pylint: disable=inconsistent-return request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -856,11 +982,10 @@ async def _refresh_member_schema_initial( # pylint: disable=inconsistent-return if cls: return cls(pipeline_response, None, {}) - _refresh_member_schema_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}/refreshSchema"} # type: ignore - + _refresh_member_schema_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}/refreshSchema"} # type: ignore @distributed_trace_async - async def begin_refresh_member_schema( # pylint: disable=inconsistent-return-statements + async def begin_refresh_member_schema( self, resource_group_name: str, server_name: str, @@ -872,19 +997,17 @@ async def begin_refresh_member_schema( # pylint: disable=inconsistent-return-st """Refreshes a sync member database schema. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. :type sync_group_name: str - :param sync_member_name: The name of the sync member. + :param sync_member_name: The name of the sync member. Required. :type sync_member_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -895,19 +1018,16 @@ async def begin_refresh_member_schema( # pylint: disable=inconsistent-return-st 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._refresh_member_schema_initial( # type: ignore resource_group_name=resource_group_name, @@ -916,34 +1036,30 @@ async def begin_refresh_member_schema( # pylint: disable=inconsistent-return-st sync_group_name=sync_group_name, sync_member_name=sync_member_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_refresh_member_schema.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}/refreshSchema"} # type: ignore + begin_refresh_member_schema.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}/refreshSchema"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_tde_certificates_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_tde_certificates_operations.py index 42cb99f61bd6a..2af721e610473 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_tde_certificates_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_tde_certificates_operations.py @@ -6,9 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar, Union, cast - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -20,10 +26,12 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._tde_certificates_operations import build_create_request_initial -T = TypeVar('T') +from ...operations._tde_certificates_operations import build_create_request + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class TdeCertificatesOperations: """ .. warning:: @@ -43,36 +51,36 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - async def _create_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - parameters: _models.TdeCertificate, - **kwargs: Any + self, resource_group_name: str, server_name: str, parameters: Union[_models.TdeCertificate, IO], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'TdeCertificate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "TdeCertificate") - request = build_create_request_initial( + request = build_create_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_initial.metadata['url'], + content=_content, + template_url=self._create_initial.metadata["url"], headers=_headers, params=_params, ) @@ -80,10 +88,9 @@ async def _create_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -93,29 +100,95 @@ async def _create_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _create_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/tdeCertificates"} # type: ignore - + _create_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/tdeCertificates"} # type: ignore - @distributed_trace_async - async def begin_create( # pylint: disable=inconsistent-return-statements + @overload + async def begin_create( self, resource_group_name: str, server_name: str, parameters: _models.TdeCertificate, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[None]: """Creates a TDE certificate for a given server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param parameters: The requested TDE certificate to be created or updated. + :param parameters: The requested TDE certificate to be created or updated. Required. :type parameters: ~azure.mgmt.sql.models.TdeCertificate - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: + """ + + @overload + async def begin_create( + self, + resource_group_name: str, + server_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Creates a TDE certificate for a given server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The requested TDE certificate to be created or updated. Required. + :type parameters: IO + :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: + """ + + @distributed_trace_async + async def begin_create( + self, resource_group_name: str, server_name: str, parameters: Union[_models.TdeCertificate, IO], **kwargs: Any + ) -> AsyncLROPoller[None]: + """Creates a TDE certificate for a given server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The requested TDE certificate to be created or updated. Is either a model + type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.TdeCertificate 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 @@ -126,20 +199,17 @@ async def begin_create( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + 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] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_initial( # type: ignore resource_group_name=resource_group_name, @@ -147,34 +217,30 @@ async def begin_create( # pylint: disable=inconsistent-return-statements parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_create.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/tdeCertificates"} # type: ignore + begin_create.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/tdeCertificates"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_time_zones_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_time_zones_operations.py index 9e6ea7695cf0c..71ad49a3e958b 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_time_zones_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_time_zones_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -21,9 +27,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._time_zones_operations import build_get_request, build_list_by_location_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class TimeZonesOperations: """ .. warning:: @@ -43,43 +51,34 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace - def list_by_location( - self, - location_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.TimeZoneListResult]: + def list_by_location(self, location_name: str, **kwargs: Any) -> AsyncIterable["_models.TimeZone"]: """Gets a list of managed instance time zones by location. - :param location_name: + :param location_name: Required. :type location_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either TimeZoneListResult or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.TimeZoneListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either TimeZone or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.TimeZone] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.TimeZoneListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.TimeZoneListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_location_request( location_name=location_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_location.metadata['url'], + template_url=self.list_by_location.metadata["url"], headers=_headers, params=_params, ) @@ -87,15 +86,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_location_request( - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -111,10 +102,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -124,51 +113,38 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/timeZones"} # type: ignore + list_by_location.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/timeZones"} # type: ignore @distributed_trace_async - async def get( - self, - location_name: str, - time_zone_id: str, - **kwargs: Any - ) -> _models.TimeZone: + async def get(self, location_name: str, time_zone_id: str, **kwargs: Any) -> _models.TimeZone: """Gets a managed instance time zone. - :param location_name: + :param location_name: Required. :type location_name: str - :param time_zone_id: + :param time_zone_id: Required. :type time_zone_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: TimeZone, or the result of cls(response) + :return: TimeZone or the result of cls(response) :rtype: ~azure.mgmt.sql.models.TimeZone - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.TimeZone] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.TimeZone] - request = build_get_request( location_name=location_name, time_zone_id=time_zone_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -176,22 +152,20 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('TimeZone', pipeline_response) + deserialized = self._deserialize("TimeZone", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/timeZones/{timeZoneId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/timeZones/{timeZoneId}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_transparent_data_encryptions_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_transparent_data_encryptions_operations.py index 978a67ed8c223..a89e7b0076231 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_transparent_data_encryptions_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_transparent_data_encryptions_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,10 +26,16 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._transparent_data_encryptions_operations import build_create_or_update_request, build_get_request, build_list_by_database_request -T = TypeVar('T') +from ...operations._transparent_data_encryptions_operations import ( + build_create_or_update_request, + build_get_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class TransparentDataEncryptionsOperations: """ .. warning:: @@ -43,7 +55,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -56,35 +67,29 @@ async def get( """Gets a logical database's transparent data encryption. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the logical database for which the transparent data - encryption is defined. + encryption is defined. Required. :type database_name: str - :param tde_name: The name of the transparent data encryption configuration. + :param tde_name: The name of the transparent data encryption configuration. "current" Required. :type tde_name: str or ~azure.mgmt.sql.models.TransparentDataEncryptionName - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: LogicalDatabaseTransparentDataEncryption, or the result of cls(response) + :return: LogicalDatabaseTransparentDataEncryption or the result of cls(response) :rtype: ~azure.mgmt.sql.models.LogicalDatabaseTransparentDataEncryption - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LogicalDatabaseTransparentDataEncryption] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LogicalDatabaseTransparentDataEncryption] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -92,7 +97,7 @@ async def get( tde_name=tde_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -100,27 +105,25 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('LogicalDatabaseTransparentDataEncryption', pipeline_response) + deserialized = self._deserialize("LogicalDatabaseTransparentDataEncryption", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption/{tdeName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption/{tdeName}"} # type: ignore - @distributed_trace_async + @overload async def create_or_update( self, resource_group_name: str, @@ -128,43 +131,118 @@ async def create_or_update( database_name: str, tde_name: Union[str, "_models.TransparentDataEncryptionName"], parameters: _models.LogicalDatabaseTransparentDataEncryption, + *, + content_type: str = "application/json", **kwargs: Any ) -> Optional[_models.LogicalDatabaseTransparentDataEncryption]: """Updates a logical database's transparent data encryption configuration. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the logical database for which the security alert policy is - defined. + defined. Required. :type database_name: str - :param tde_name: The name of the transparent data encryption configuration. + :param tde_name: The name of the transparent data encryption configuration. "current" Required. :type tde_name: str or ~azure.mgmt.sql.models.TransparentDataEncryptionName - :param parameters: The database transparent data encryption. + :param parameters: The database transparent data encryption. Required. :type parameters: ~azure.mgmt.sql.models.LogicalDatabaseTransparentDataEncryption - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: LogicalDatabaseTransparentDataEncryption or None or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.LogicalDatabaseTransparentDataEncryption or None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + tde_name: Union[str, "_models.TransparentDataEncryptionName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> Optional[_models.LogicalDatabaseTransparentDataEncryption]: + """Updates a logical database's transparent data encryption configuration. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the logical database for which the security alert policy is + defined. Required. + :type database_name: str + :param tde_name: The name of the transparent data encryption configuration. "current" Required. + :type tde_name: str or ~azure.mgmt.sql.models.TransparentDataEncryptionName + :param parameters: The database transparent data encryption. Required. + :type parameters: IO + :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: LogicalDatabaseTransparentDataEncryption or None or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.LogicalDatabaseTransparentDataEncryption or None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + tde_name: Union[str, "_models.TransparentDataEncryptionName"], + parameters: Union[_models.LogicalDatabaseTransparentDataEncryption, IO], + **kwargs: Any + ) -> Optional[_models.LogicalDatabaseTransparentDataEncryption]: + """Updates a logical database's transparent data encryption configuration. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the logical database for which the security alert policy is + defined. Required. + :type database_name: str + :param tde_name: The name of the transparent data encryption configuration. "current" Required. + :type tde_name: str or ~azure.mgmt.sql.models.TransparentDataEncryptionName + :param parameters: The database transparent data encryption. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.LogicalDatabaseTransparentDataEncryption 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 - :return: LogicalDatabaseTransparentDataEncryption, or the result of cls(response) + :return: LogicalDatabaseTransparentDataEncryption or None or the result of cls(response) :rtype: ~azure.mgmt.sql.models.LogicalDatabaseTransparentDataEncryption or None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.LogicalDatabaseTransparentDataEncryption]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.LogicalDatabaseTransparentDataEncryption]] - _json = self._serialize.body(parameters, 'LogicalDatabaseTransparentDataEncryption') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "LogicalDatabaseTransparentDataEncryption") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -175,7 +253,8 @@ async def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -183,10 +262,9 @@ async def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -195,67 +273,58 @@ async def create_or_update( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('LogicalDatabaseTransparentDataEncryption', pipeline_response) + deserialized = self._deserialize("LogicalDatabaseTransparentDataEncryption", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('LogicalDatabaseTransparentDataEncryption', pipeline_response) + deserialized = self._deserialize("LogicalDatabaseTransparentDataEncryption", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption/{tdeName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption/{tdeName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.LogicalDatabaseTransparentDataEncryptionListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.LogicalDatabaseTransparentDataEncryption"]: """Gets a list of the logical database's transparent data encryption. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the logical database for which the transparent data - encryption is defined. + encryption is defined. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LogicalDatabaseTransparentDataEncryptionListResult - or the result of cls(response) + :return: An iterator like instance of either LogicalDatabaseTransparentDataEncryption or the + result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LogicalDatabaseTransparentDataEncryptionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.LogicalDatabaseTransparentDataEncryption] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LogicalDatabaseTransparentDataEncryptionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LogicalDatabaseTransparentDataEncryptionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -263,17 +332,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -289,10 +348,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -302,8 +359,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_usages_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_usages_operations.py index 31208858b5b26..0c3a89270e770 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_usages_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_usages_operations.py @@ -9,7 +9,13 @@ from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.rest import HttpRequest @@ -20,9 +26,11 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._usages_operations import build_list_by_instance_pool_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class UsagesOperations: """ .. warning:: @@ -42,53 +50,44 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance_pool( - self, - resource_group_name: str, - instance_pool_name: str, - expand_children: Optional[bool] = None, - **kwargs: Any - ) -> AsyncIterable[_models.UsageListResult]: + self, resource_group_name: str, instance_pool_name: str, expand_children: Optional[bool] = None, **kwargs: Any + ) -> AsyncIterable["_models.Usage"]: """Gets all instance pool usage metrics. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param instance_pool_name: The name of the instance pool to be retrieved. + :param instance_pool_name: The name of the instance pool to be retrieved. Required. :type instance_pool_name: str :param expand_children: Optional request parameter to include managed instance usages within the instance pool. Default value is None. :type expand_children: bool - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either UsageListResult or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.UsageListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Usage or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.Usage] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.UsageListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.UsageListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_pool_request( resource_group_name=resource_group_name, instance_pool_name=instance_pool_name, subscription_id=self._config.subscription_id, - api_version=api_version, expand_children=expand_children, - template_url=self.list_by_instance_pool.metadata['url'], + api_version=api_version, + template_url=self.list_by_instance_pool.metadata["url"], headers=_headers, params=_params, ) @@ -96,17 +95,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_pool_request( - resource_group_name=resource_group_name, - instance_pool_name=instance_pool_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - expand_children=expand_children, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -122,10 +111,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -135,8 +122,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_instance_pool.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}/usages"} # type: ignore + list_by_instance_pool.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}/usages"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_virtual_clusters_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_virtual_clusters_operations.py index 36c5a5fa5af9a..2ca4d1a07a06c 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_virtual_clusters_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_virtual_clusters_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,19 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._virtual_clusters_operations import build_delete_request_initial, build_get_request, build_list_by_resource_group_request, build_list_request, build_update_dns_servers_request, build_update_request_initial -T = TypeVar('T') +from ...operations._virtual_clusters_operations import ( + build_delete_request, + build_get_request, + build_list_by_resource_group_request, + build_list_request, + build_update_dns_servers_request, + build_update_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class VirtualClustersOperations: """ .. warning:: @@ -45,48 +60,38 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def update_dns_servers( - self, - resource_group_name: str, - virtual_cluster_name: str, - **kwargs: Any + self, resource_group_name: str, virtual_cluster_name: str, **kwargs: Any ) -> _models.UpdateManagedInstanceDnsServersOperation: """Synchronizes the DNS server settings used by the managed instances inside the given virtual cluster. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param virtual_cluster_name: The name of the virtual cluster. + :param virtual_cluster_name: The name of the virtual cluster. Required. :type virtual_cluster_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: UpdateManagedInstanceDnsServersOperation, or the result of cls(response) + :return: UpdateManagedInstanceDnsServersOperation or the result of cls(response) :rtype: ~azure.mgmt.sql.models.UpdateManagedInstanceDnsServersOperation - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.UpdateManagedInstanceDnsServersOperation] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.UpdateManagedInstanceDnsServersOperation] - request = build_update_dns_servers_request( resource_group_name=resource_group_name, virtual_cluster_name=virtual_cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.update_dns_servers.metadata['url'], + template_url=self.update_dns_servers.metadata["url"], headers=_headers, params=_params, ) @@ -94,60 +99,49 @@ async def update_dns_servers( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('UpdateManagedInstanceDnsServersOperation', pipeline_response) + deserialized = self._deserialize("UpdateManagedInstanceDnsServersOperation", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - update_dns_servers.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}/updateManagedInstanceDnsServers"} # type: ignore - + update_dns_servers.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}/updateManagedInstanceDnsServers"} # type: ignore @distributed_trace - def list( - self, - **kwargs: Any - ) -> AsyncIterable[_models.VirtualClusterListResult]: + def list(self, **kwargs: Any) -> AsyncIterable["_models.VirtualCluster"]: """Gets a list of all virtualClusters in the subscription. - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VirtualClusterListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.VirtualClusterListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either VirtualCluster or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.VirtualCluster] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VirtualClusterListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualClusterListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_request( subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list.metadata['url'], + template_url=self.list.metadata["url"], headers=_headers, params=_params, ) @@ -155,14 +149,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_request( - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -178,10 +165,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -191,51 +176,41 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/virtualClusters"} # type: ignore + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/virtualClusters"} # type: ignore @distributed_trace def list_by_resource_group( - self, - resource_group_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.VirtualClusterListResult]: + self, resource_group_name: str, **kwargs: Any + ) -> AsyncIterable["_models.VirtualCluster"]: """Gets a list of virtual clusters in a resource group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VirtualClusterListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.VirtualClusterListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either VirtualCluster or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.VirtualCluster] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VirtualClusterListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualClusterListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_request( resource_group_name=resource_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_resource_group.metadata['url'], + template_url=self.list_by_resource_group.metadata["url"], headers=_headers, params=_params, ) @@ -243,15 +218,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -267,10 +234,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -280,52 +245,39 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters"} # type: ignore + list_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters"} # type: ignore @distributed_trace_async - async def get( - self, - resource_group_name: str, - virtual_cluster_name: str, - **kwargs: Any - ) -> _models.VirtualCluster: + async def get(self, resource_group_name: str, virtual_cluster_name: str, **kwargs: Any) -> _models.VirtualCluster: """Gets a virtual cluster. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param virtual_cluster_name: The name of the virtual cluster. + :param virtual_cluster_name: The name of the virtual cluster. Required. :type virtual_cluster_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VirtualCluster, or the result of cls(response) + :return: VirtualCluster or the result of cls(response) :rtype: ~azure.mgmt.sql.models.VirtualCluster - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VirtualCluster] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualCluster] - request = build_get_request( resource_group_name=resource_group_name, virtual_cluster_name=virtual_cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -333,50 +285,42 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('VirtualCluster', pipeline_response) + deserialized = self._deserialize("VirtualCluster", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - virtual_cluster_name: str, - **kwargs: Any + self, resource_group_name: str, virtual_cluster_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, virtual_cluster_name=virtual_cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -384,10 +328,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -397,26 +340,19 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - virtual_cluster_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, virtual_cluster_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes a virtual cluster. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param virtual_cluster_name: The name of the virtual cluster. + :param virtual_cluster_name: The name of the virtual cluster. Required. :type virtual_cluster_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -427,85 +363,83 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, virtual_cluster_name=virtual_cluster_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/virtualClusters/{virtualClusterName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore async def _update_initial( self, resource_group_name: str, virtual_cluster_name: str, - parameters: _models.VirtualClusterUpdate, + parameters: Union[_models.VirtualClusterUpdate, IO], **kwargs: Any ) -> Optional[_models.VirtualCluster]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.VirtualCluster]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.VirtualCluster]] - _json = self._serialize.body(parameters, 'VirtualClusterUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "VirtualClusterUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, virtual_cluster_name=virtual_cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -513,10 +447,9 @@ async def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -525,36 +458,73 @@ async def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('VirtualCluster', pipeline_response) + deserialized = self._deserialize("VirtualCluster", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore - - @distributed_trace_async + @overload async def begin_update( self, resource_group_name: str, virtual_cluster_name: str, parameters: _models.VirtualClusterUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.VirtualCluster]: """Updates a virtual cluster. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param virtual_cluster_name: The name of the virtual cluster. + :param virtual_cluster_name: The name of the virtual cluster. Required. :type virtual_cluster_name: str - :param parameters: The requested virtual cluster resource state. + :param parameters: The requested virtual cluster resource state. Required. :type parameters: ~azure.mgmt.sql.models.VirtualClusterUpdate - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 VirtualCluster or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.VirtualCluster] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_update( + self, + resource_group_name: str, + virtual_cluster_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.VirtualCluster]: + """Updates a virtual cluster. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param virtual_cluster_name: The name of the virtual cluster. Required. + :type virtual_cluster_name: str + :param parameters: The requested virtual cluster resource state. Required. + :type parameters: IO + :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 @@ -566,20 +536,52 @@ async def begin_update( :return: An instance of AsyncLROPoller that returns either VirtualCluster or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.VirtualCluster] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_update( + self, + resource_group_name: str, + virtual_cluster_name: str, + parameters: Union[_models.VirtualClusterUpdate, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.VirtualCluster]: + """Updates a virtual cluster. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param virtual_cluster_name: The name of the virtual cluster. Required. + :type virtual_cluster_name: str + :param parameters: The requested virtual cluster resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.VirtualClusterUpdate 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. + :return: An instance of AsyncLROPoller that returns either VirtualCluster or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.VirtualCluster] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.VirtualCluster] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualCluster] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -587,36 +589,32 @@ async def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('VirtualCluster', pipeline_response) + deserialized = self._deserialize("VirtualCluster", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_virtual_network_rules_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_virtual_network_rules_operations.py index c584613dfbad1..1cf1ba0698b4c 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_virtual_network_rules_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_virtual_network_rules_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._virtual_network_rules_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_server_request -T = TypeVar('T') +from ...operations._virtual_network_rules_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_server_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class VirtualNetworkRulesOperations: """ .. warning:: @@ -45,51 +58,40 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - virtual_network_rule_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, virtual_network_rule_name: str, **kwargs: Any ) -> _models.VirtualNetworkRule: """Gets a virtual network rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param virtual_network_rule_name: The name of the virtual network rule. + :param virtual_network_rule_name: The name of the virtual network rule. Required. :type virtual_network_rule_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VirtualNetworkRule, or the result of cls(response) + :return: VirtualNetworkRule or the result of cls(response) :rtype: ~azure.mgmt.sql.models.VirtualNetworkRule - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VirtualNetworkRule] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualNetworkRule] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, virtual_network_rule_name=virtual_network_rule_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -97,49 +99,51 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('VirtualNetworkRule', pipeline_response) + deserialized = self._deserialize("VirtualNetworkRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore async def _create_or_update_initial( self, resource_group_name: str, server_name: str, virtual_network_rule_name: str, - parameters: _models.VirtualNetworkRule, + parameters: Union[_models.VirtualNetworkRule, IO], **kwargs: Any ) -> Optional[_models.VirtualNetworkRule]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.VirtualNetworkRule]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.VirtualNetworkRule]] - _json = self._serialize.body(parameters, 'VirtualNetworkRule') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "VirtualNetworkRule") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, virtual_network_rule_name=virtual_network_rule_name, @@ -147,7 +151,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -155,10 +160,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -167,42 +171,120 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('VirtualNetworkRule', pipeline_response) + deserialized = self._deserialize("VirtualNetworkRule", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('VirtualNetworkRule', pipeline_response) + deserialized = self._deserialize("VirtualNetworkRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, server_name: str, virtual_network_rule_name: str, parameters: _models.VirtualNetworkRule, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.VirtualNetworkRule]: """Creates or updates an existing virtual network rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param virtual_network_rule_name: The name of the virtual network rule. + :param virtual_network_rule_name: The name of the virtual network rule. Required. :type virtual_network_rule_name: str - :param parameters: The requested virtual Network Rule Resource state. + :param parameters: The requested virtual Network Rule Resource state. Required. :type parameters: ~azure.mgmt.sql.models.VirtualNetworkRule - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 VirtualNetworkRule or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.VirtualNetworkRule] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + virtual_network_rule_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.VirtualNetworkRule]: + """Creates or updates an existing virtual network rule. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param virtual_network_rule_name: The name of the virtual network rule. Required. + :type virtual_network_rule_name: str + :param parameters: The requested virtual Network Rule Resource state. Required. + :type parameters: IO + :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 VirtualNetworkRule or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.VirtualNetworkRule] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + virtual_network_rule_name: str, + parameters: Union[_models.VirtualNetworkRule, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.VirtualNetworkRule]: + """Creates or updates an existing virtual network rule. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param virtual_network_rule_name: The name of the virtual network rule. Required. + :type virtual_network_rule_name: str + :param parameters: The requested virtual Network Rule Resource state. Is either a model type or + a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.VirtualNetworkRule 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 @@ -214,20 +296,17 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either VirtualNetworkRule or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.VirtualNetworkRule] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.VirtualNetworkRule] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualNetworkRule] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -236,66 +315,55 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('VirtualNetworkRule', pipeline_response) + deserialized = self._deserialize("VirtualNetworkRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - virtual_network_rule_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, virtual_network_rule_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, virtual_network_rule_name=virtual_network_rule_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -303,10 +371,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -316,29 +383,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - virtual_network_rule_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, server_name: str, virtual_network_rule_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes the virtual network rule with the given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param virtual_network_rule_name: The name of the virtual network rule. + :param virtual_network_rule_name: The name of the virtual network rule. Required. :type virtual_network_rule_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -349,100 +408,84 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, virtual_network_rule_name=virtual_network_rule_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.VirtualNetworkRuleListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> AsyncIterable["_models.VirtualNetworkRule"]: """Gets a list of virtual network rules in a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VirtualNetworkRuleListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.VirtualNetworkRuleListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either VirtualNetworkRule or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.VirtualNetworkRule] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VirtualNetworkRuleListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualNetworkRuleListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -450,16 +493,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -475,10 +509,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -488,8 +520,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_workload_classifiers_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_workload_classifiers_operations.py index 587bb5f6cb1d6..010f5a8fe1d5e 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_workload_classifiers_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_workload_classifiers_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._workload_classifiers_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_workload_group_request -T = TypeVar('T') +from ...operations._workload_classifiers_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_workload_group_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class WorkloadClassifiersOperations: """ .. warning:: @@ -45,7 +58,6 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( self, @@ -59,37 +71,31 @@ async def get( """Gets a workload classifier. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param workload_group_name: The name of the workload group from which to receive the classifier - from. + from. Required. :type workload_group_name: str - :param workload_classifier_name: The name of the workload classifier. + :param workload_classifier_name: The name of the workload classifier. Required. :type workload_classifier_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: WorkloadClassifier, or the result of cls(response) + :return: WorkloadClassifier or the result of cls(response) :rtype: ~azure.mgmt.sql.models.WorkloadClassifier - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.WorkloadClassifier] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.WorkloadClassifier] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -98,7 +104,7 @@ async def get( workload_classifier_name=workload_classifier_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -106,25 +112,23 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('WorkloadClassifier', pipeline_response) + deserialized = self._deserialize("WorkloadClassifier", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore async def _create_or_update_initial( self, @@ -133,24 +137,28 @@ async def _create_or_update_initial( database_name: str, workload_group_name: str, workload_classifier_name: str, - parameters: _models.WorkloadClassifier, + parameters: Union[_models.WorkloadClassifier, IO], **kwargs: Any ) -> Optional[_models.WorkloadClassifier]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.WorkloadClassifier]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.WorkloadClassifier]] - _json = self._serialize.body(parameters, 'WorkloadClassifier') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "WorkloadClassifier") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -160,7 +168,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -168,10 +177,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -180,20 +188,19 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('WorkloadClassifier', pipeline_response) + deserialized = self._deserialize("WorkloadClassifier", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('WorkloadClassifier', pipeline_response) + deserialized = self._deserialize("WorkloadClassifier", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, @@ -202,27 +209,77 @@ async def begin_create_or_update( workload_group_name: str, workload_classifier_name: str, parameters: _models.WorkloadClassifier, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.WorkloadClassifier]: """Creates or updates a workload classifier. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param workload_group_name: The name of the workload group from which to receive the classifier - from. + from. Required. :type workload_group_name: str :param workload_classifier_name: The name of the workload classifier to create/update. + Required. :type workload_classifier_name: str - :param parameters: The properties of the workload classifier. + :param parameters: The properties of the workload classifier. Required. :type parameters: ~azure.mgmt.sql.models.WorkloadClassifier - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 WorkloadClassifier or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.WorkloadClassifier] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + workload_group_name: str, + workload_classifier_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.WorkloadClassifier]: + """Creates or updates a workload classifier. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param workload_group_name: The name of the workload group from which to receive the classifier + from. Required. + :type workload_group_name: str + :param workload_classifier_name: The name of the workload classifier to create/update. + Required. + :type workload_classifier_name: str + :param parameters: The properties of the workload classifier. Required. + :type parameters: IO + :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 @@ -234,20 +291,63 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either WorkloadClassifier or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.WorkloadClassifier] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + workload_group_name: str, + workload_classifier_name: str, + parameters: Union[_models.WorkloadClassifier, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.WorkloadClassifier]: + """Creates or updates a workload classifier. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param workload_group_name: The name of the workload group from which to receive the classifier + from. Required. + :type workload_group_name: str + :param workload_classifier_name: The name of the workload classifier to create/update. + Required. + :type workload_classifier_name: str + :param parameters: The properties of the workload classifier. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.WorkloadClassifier 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. + :return: An instance of AsyncLROPoller that returns either WorkloadClassifier or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.WorkloadClassifier] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.WorkloadClassifier] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.WorkloadClassifier] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -258,39 +358,35 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('WorkloadClassifier', pipeline_response) + deserialized = self._deserialize("WorkloadClassifier", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements self, @@ -301,19 +397,16 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements workload_classifier_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -321,7 +414,7 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements workload_classifier_name=workload_classifier_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -329,10 +422,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -342,11 +434,10 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements + async def begin_delete( self, resource_group_name: str, server_name: str, @@ -358,20 +449,17 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements """Deletes a workload classifier. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param workload_group_name: The name of the workload group from which to receive the classifier - from. + from. Required. :type workload_group_name: str - :param workload_classifier_name: The name of the workload classifier to delete. + :param workload_classifier_name: The name of the workload classifier to delete. Required. :type workload_classifier_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -382,19 +470,16 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, @@ -403,82 +488,67 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements workload_group_name=workload_group_name, workload_classifier_name=workload_classifier_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore @distributed_trace def list_by_workload_group( - self, - resource_group_name: str, - server_name: str, - database_name: str, - workload_group_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.WorkloadClassifierListResult]: + self, resource_group_name: str, server_name: str, database_name: str, workload_group_name: str, **kwargs: Any + ) -> AsyncIterable["_models.WorkloadClassifier"]: """Gets the list of workload classifiers for a workload group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param workload_group_name: The name of the workload group from which to receive the - classifiers from. + classifiers from. Required. :type workload_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either WorkloadClassifierListResult or the result of - cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.WorkloadClassifierListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either WorkloadClassifier or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.WorkloadClassifier] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.WorkloadClassifierListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.WorkloadClassifierListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_workload_group_request( resource_group_name=resource_group_name, server_name=server_name, @@ -486,7 +556,7 @@ def prepare_request(next_link=None): workload_group_name=workload_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_workload_group.metadata['url'], + template_url=self.list_by_workload_group.metadata["url"], headers=_headers, params=_params, ) @@ -494,18 +564,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_workload_group_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - workload_group_name=workload_group_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -521,10 +580,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -534,8 +591,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_workload_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers"} # type: ignore + list_by_workload_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_workload_groups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_workload_groups_operations.py index 5af13b5f05e4e..3aac1c82d0991 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_workload_groups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/aio/operations/_workload_groups_operations.py @@ -6,10 +6,16 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod @@ -22,10 +28,17 @@ from ... import models as _models from ..._vendor import _convert_request -from ...operations._workload_groups_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_database_request -T = TypeVar('T') +from ...operations._workload_groups_operations import ( + build_create_or_update_request, + build_delete_request, + build_get_request, + build_list_by_database_request, +) + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + class WorkloadGroupsOperations: """ .. warning:: @@ -45,47 +58,35 @@ def __init__(self, *args, **kwargs) -> None: self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace_async async def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - workload_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, workload_group_name: str, **kwargs: Any ) -> _models.WorkloadGroup: """Gets a workload group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param workload_group_name: The name of the workload group. + :param workload_group_name: The name of the workload group. Required. :type workload_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: WorkloadGroup, or the result of cls(response) + :return: WorkloadGroup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.WorkloadGroup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.WorkloadGroup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.WorkloadGroup] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -93,7 +94,7 @@ async def get( workload_group_name=workload_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -101,25 +102,23 @@ async def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('WorkloadGroup', pipeline_response) + deserialized = self._deserialize("WorkloadGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore async def _create_or_update_initial( self, @@ -127,24 +126,28 @@ async def _create_or_update_initial( server_name: str, database_name: str, workload_group_name: str, - parameters: _models.WorkloadGroup, + parameters: Union[_models.WorkloadGroup, IO], **kwargs: Any ) -> Optional[_models.WorkloadGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.WorkloadGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.WorkloadGroup]] - _json = self._serialize.body(parameters, 'WorkloadGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "WorkloadGroup") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -153,7 +156,8 @@ async def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -161,10 +165,9 @@ async def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -173,20 +176,19 @@ async def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('WorkloadGroup', pipeline_response) + deserialized = self._deserialize("WorkloadGroup", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('WorkloadGroup', pipeline_response) + deserialized = self._deserialize("WorkloadGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore - @distributed_trace_async + @overload async def begin_create_or_update( self, resource_group_name: str, @@ -194,24 +196,68 @@ async def begin_create_or_update( database_name: str, workload_group_name: str, parameters: _models.WorkloadGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> AsyncLROPoller[_models.WorkloadGroup]: """Creates or updates a workload group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param workload_group_name: The name of the workload group. + :param workload_group_name: The name of the workload group. Required. :type workload_group_name: str - :param parameters: The requested workload group state. + :param parameters: The requested workload group state. Required. :type parameters: ~azure.mgmt.sql.models.WorkloadGroup - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 WorkloadGroup or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.WorkloadGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + workload_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.WorkloadGroup]: + """Creates or updates a workload group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param workload_group_name: The name of the workload group. Required. + :type workload_group_name: str + :param parameters: The requested workload group state. Required. + :type parameters: IO + :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 @@ -223,20 +269,58 @@ async def begin_create_or_update( :return: An instance of AsyncLROPoller that returns either WorkloadGroup or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.WorkloadGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + workload_group_name: str, + parameters: Union[_models.WorkloadGroup, IO], + **kwargs: Any + ) -> AsyncLROPoller[_models.WorkloadGroup]: + """Creates or updates a workload group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param workload_group_name: The name of the workload group. Required. + :type workload_group_name: str + :param parameters: The requested workload group state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.WorkloadGroup 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. + :return: An instance of AsyncLROPoller that returns either WorkloadGroup or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.sql.models.WorkloadGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.WorkloadGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.WorkloadGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -246,68 +330,56 @@ async def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('WorkloadGroup', pipeline_response) + deserialized = self._deserialize("WorkloadGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - workload_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, workload_group_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, workload_group_name=workload_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -315,10 +387,9 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -328,32 +399,23 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore @distributed_trace_async - async def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - workload_group_name: str, - **kwargs: Any + async def begin_delete( + self, resource_group_name: str, server_name: str, database_name: str, workload_group_name: str, **kwargs: Any ) -> AsyncLROPoller[None]: """Deletes a workload group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param workload_group_name: The name of the workload group to delete. + :param workload_group_name: The name of the workload group to delete. Required. :type workload_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -364,19 +426,16 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = await self._delete_initial( # type: ignore resource_group_name=resource_group_name, @@ -384,84 +443,71 @@ async def begin_delete( # pylint: disable=inconsistent-return-statements database_name=database_name, workload_group_name=workload_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling( - lro_delay, - - - **kwargs - )) # type: AsyncPollingMethod - elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: polling_method = polling + polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling if cont_token: return AsyncLROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> AsyncIterable[_models.WorkloadGroupListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> AsyncIterable["_models.WorkloadGroup"]: """Gets the list of workload groups. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either WorkloadGroupListResult or the result of - cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.WorkloadGroupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either WorkloadGroup or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.sql.models.WorkloadGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.WorkloadGroupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.WorkloadGroupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -469,17 +515,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -495,10 +531,8 @@ async def extract_data(pipeline_response): async def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -508,8 +542,6 @@ async def get_next(next_link=None): return pipeline_response + return AsyncItemPaged(get_next, extract_data) - return AsyncItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/models/__init__.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/models/__init__.py index 2f1e6cc8375a7..1c9fe96d60c21 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/models/__init__.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/models/__init__.py @@ -149,16 +149,28 @@ from ._models_py3 import ManagedBackupShortTermRetentionPolicy from ._models_py3 import ManagedBackupShortTermRetentionPolicyListResult from ._models_py3 import ManagedDatabase +from ._models_py3 import ManagedDatabaseAdvancedThreatProtection +from ._models_py3 import ManagedDatabaseAdvancedThreatProtectionListResult from ._models_py3 import ManagedDatabaseListResult +from ._models_py3 import ManagedDatabaseMoveDefinition +from ._models_py3 import ManagedDatabaseRestoreDetailsBackupSetProperties from ._models_py3 import ManagedDatabaseRestoreDetailsResult +from ._models_py3 import ManagedDatabaseRestoreDetailsUnrestorableFileProperties from ._models_py3 import ManagedDatabaseSecurityAlertPolicy from ._models_py3 import ManagedDatabaseSecurityAlertPolicyListResult +from ._models_py3 import ManagedDatabaseStartMoveDefinition from ._models_py3 import ManagedDatabaseUpdate from ._models_py3 import ManagedInstance from ._models_py3 import ManagedInstanceAdministrator from ._models_py3 import ManagedInstanceAdministratorListResult +from ._models_py3 import ManagedInstanceAdvancedThreatProtection +from ._models_py3 import ManagedInstanceAdvancedThreatProtectionListResult from ._models_py3 import ManagedInstanceAzureADOnlyAuthListResult from ._models_py3 import ManagedInstanceAzureADOnlyAuthentication +from ._models_py3 import ManagedInstanceDtc +from ._models_py3 import ManagedInstanceDtcListResult +from ._models_py3 import ManagedInstanceDtcSecuritySettings +from ._models_py3 import ManagedInstanceDtcTransactionManagerCommunicationSettings from ._models_py3 import ManagedInstanceEditionCapability from ._models_py3 import ManagedInstanceEncryptionProtector from ._models_py3 import ManagedInstanceEncryptionProtectorListResult @@ -363,639 +375,653 @@ from ._models_py3 import WorkloadGroup from ._models_py3 import WorkloadGroupListResult - -from ._sql_management_client_enums import ( - AdministratorName, - AdministratorType, - AdvancedThreatProtectionName, - AdvancedThreatProtectionState, - AdvisorStatus, - AggregationFunctionType, - AuthenticationName, - AutoExecuteStatus, - AutoExecuteStatusInheritedFrom, - AutomaticTuningDisabledReason, - AutomaticTuningMode, - AutomaticTuningOptionModeActual, - AutomaticTuningOptionModeDesired, - AutomaticTuningServerMode, - AutomaticTuningServerReason, - BackupStorageRedundancy, - BlobAuditingPolicyState, - CapabilityGroup, - CapabilityStatus, - CatalogCollationType, - CheckNameAvailabilityReason, - ColumnDataType, - ConnectionPolicyName, - CreateMode, - CreatedByType, - DataMaskingFunction, - DataMaskingRuleState, - DataMaskingState, - DataWarehouseUserActivityName, - DatabaseIdentityType, - DatabaseLicenseType, - DatabaseReadScale, - DatabaseState, - DatabaseStatus, - DayOfWeek, - DiffBackupIntervalInHours, - DnsRefreshConfigurationPropertiesStatus, - ElasticPoolLicenseType, - ElasticPoolState, - EncryptionProtectorName, - FailoverGroupReplicationRole, - GeoBackupPolicyName, - GeoBackupPolicyState, - IdentityType, - ImplementationMethod, - InstanceFailoverGroupReplicationRole, - InstancePoolLicenseType, - IsRetryable, - JobAgentState, - JobExecutionLifecycle, - JobScheduleType, - JobStepActionSource, - JobStepActionType, - JobStepOutputType, - JobTargetGroupMembershipType, - JobTargetType, - LedgerDigestUploadsName, - LedgerDigestUploadsState, - LogSizeUnit, - LongTermRetentionPolicyName, - ManagedDatabaseCreateMode, - ManagedDatabaseStatus, - ManagedInstanceAdministratorType, - ManagedInstanceLicenseType, - ManagedInstanceLongTermRetentionPolicyName, - ManagedInstancePropertiesProvisioningState, - ManagedInstanceProxyOverride, - ManagedServerCreateMode, - ManagedShortTermRetentionPolicyName, - ManagementOperationState, - MaxSizeUnit, - MetricType, - OperationMode, - OperationOrigin, - PauseDelayTimeUnit, - PerformanceLevelUnit, - PrimaryAggregationType, - PrincipalType, - PrivateEndpointProvisioningState, - PrivateLinkServiceConnectionStateActionsRequire, - PrivateLinkServiceConnectionStateStatus, - ProvisioningState, - QueryMetricUnitType, - QueryTimeGrainType, - ReadOnlyEndpointFailoverPolicy, - ReadWriteEndpointFailoverPolicy, - RecommendedActionCurrentState, - RecommendedActionInitiatedBy, - RecommendedSensitivityLabelUpdateKind, - ReplicaType, - ReplicationLinkType, - ReplicationMode, - ReplicationRole, - ReplicationState, - RestoreDetailsName, - RestorePointType, - SampleName, - SecondaryType, - SecurityAlertPolicyName, - SecurityAlertPolicyState, - SecurityAlertsPolicyState, - SecurityEventType, - SensitivityLabelRank, - SensitivityLabelSource, - SensitivityLabelUpdateKind, - ServerConnectionType, - ServerKeyType, - ServerNetworkAccessFlag, - ServerTrustGroupPropertiesTrustScopesItem, - ServerWorkspaceFeature, - ServiceObjectiveName, - ServicePrincipalType, - ShortTermRetentionPolicyName, - SqlAgentConfigurationPropertiesState, - StorageCapabilityStorageAccountType, - StorageKeyType, - SyncAgentState, - SyncConflictResolutionPolicy, - SyncDirection, - SyncGroupLogType, - SyncGroupState, - SyncGroupsType, - SyncMemberDbType, - SyncMemberState, - TableTemporalType, - TransparentDataEncryptionName, - TransparentDataEncryptionState, - UnitDefinitionType, - UnitType, - UpsertManagedServerOperationStepStatus, - VirtualNetworkRuleState, - VulnerabilityAssessmentName, - VulnerabilityAssessmentPolicyBaselineName, - VulnerabilityAssessmentScanState, - VulnerabilityAssessmentScanTriggerType, -) +from ._sql_management_client_enums import AdministratorName +from ._sql_management_client_enums import AdministratorType +from ._sql_management_client_enums import AdvancedThreatProtectionName +from ._sql_management_client_enums import AdvancedThreatProtectionState +from ._sql_management_client_enums import AdvisorStatus +from ._sql_management_client_enums import AggregationFunctionType +from ._sql_management_client_enums import AuthenticationName +from ._sql_management_client_enums import AutoExecuteStatus +from ._sql_management_client_enums import AutoExecuteStatusInheritedFrom +from ._sql_management_client_enums import AutomaticTuningDisabledReason +from ._sql_management_client_enums import AutomaticTuningMode +from ._sql_management_client_enums import AutomaticTuningOptionModeActual +from ._sql_management_client_enums import AutomaticTuningOptionModeDesired +from ._sql_management_client_enums import AutomaticTuningServerMode +from ._sql_management_client_enums import AutomaticTuningServerReason +from ._sql_management_client_enums import BackupStorageRedundancy +from ._sql_management_client_enums import BlobAuditingPolicyState +from ._sql_management_client_enums import CapabilityGroup +from ._sql_management_client_enums import CapabilityStatus +from ._sql_management_client_enums import CatalogCollationType +from ._sql_management_client_enums import CheckNameAvailabilityReason +from ._sql_management_client_enums import ColumnDataType +from ._sql_management_client_enums import ConnectionPolicyName +from ._sql_management_client_enums import CreateMode +from ._sql_management_client_enums import CreatedByType +from ._sql_management_client_enums import DataMaskingFunction +from ._sql_management_client_enums import DataMaskingRuleState +from ._sql_management_client_enums import DataMaskingState +from ._sql_management_client_enums import DataWarehouseUserActivityName +from ._sql_management_client_enums import DatabaseIdentityType +from ._sql_management_client_enums import DatabaseLicenseType +from ._sql_management_client_enums import DatabaseReadScale +from ._sql_management_client_enums import DatabaseState +from ._sql_management_client_enums import DatabaseStatus +from ._sql_management_client_enums import DayOfWeek +from ._sql_management_client_enums import DiffBackupIntervalInHours +from ._sql_management_client_enums import DnsRefreshConfigurationPropertiesStatus +from ._sql_management_client_enums import DtcName +from ._sql_management_client_enums import ElasticPoolLicenseType +from ._sql_management_client_enums import ElasticPoolState +from ._sql_management_client_enums import EncryptionProtectorName +from ._sql_management_client_enums import FailoverGroupReplicationRole +from ._sql_management_client_enums import GeoBackupPolicyName +from ._sql_management_client_enums import GeoBackupPolicyState +from ._sql_management_client_enums import IdentityType +from ._sql_management_client_enums import ImplementationMethod +from ._sql_management_client_enums import InstanceFailoverGroupReplicationRole +from ._sql_management_client_enums import InstancePoolLicenseType +from ._sql_management_client_enums import IsRetryable +from ._sql_management_client_enums import JobAgentState +from ._sql_management_client_enums import JobExecutionLifecycle +from ._sql_management_client_enums import JobScheduleType +from ._sql_management_client_enums import JobStepActionSource +from ._sql_management_client_enums import JobStepActionType +from ._sql_management_client_enums import JobStepOutputType +from ._sql_management_client_enums import JobTargetGroupMembershipType +from ._sql_management_client_enums import JobTargetType +from ._sql_management_client_enums import LedgerDigestUploadsName +from ._sql_management_client_enums import LedgerDigestUploadsState +from ._sql_management_client_enums import LogSizeUnit +from ._sql_management_client_enums import LongTermRetentionPolicyName +from ._sql_management_client_enums import ManagedDatabaseCreateMode +from ._sql_management_client_enums import ManagedDatabaseStatus +from ._sql_management_client_enums import ManagedInstanceAdministratorType +from ._sql_management_client_enums import ManagedInstanceLicenseType +from ._sql_management_client_enums import ManagedInstanceLongTermRetentionPolicyName +from ._sql_management_client_enums import ManagedInstancePropertiesProvisioningState +from ._sql_management_client_enums import ManagedInstanceProxyOverride +from ._sql_management_client_enums import ManagedServerCreateMode +from ._sql_management_client_enums import ManagedShortTermRetentionPolicyName +from ._sql_management_client_enums import ManagementOperationState +from ._sql_management_client_enums import MaxSizeUnit +from ._sql_management_client_enums import MetricType +from ._sql_management_client_enums import MoveOperationMode +from ._sql_management_client_enums import OperationMode +from ._sql_management_client_enums import OperationOrigin +from ._sql_management_client_enums import PauseDelayTimeUnit +from ._sql_management_client_enums import PerformanceLevelUnit +from ._sql_management_client_enums import PrimaryAggregationType +from ._sql_management_client_enums import PrincipalType +from ._sql_management_client_enums import PrivateEndpointProvisioningState +from ._sql_management_client_enums import PrivateLinkServiceConnectionStateActionsRequire +from ._sql_management_client_enums import PrivateLinkServiceConnectionStateStatus +from ._sql_management_client_enums import ProvisioningState +from ._sql_management_client_enums import QueryMetricUnitType +from ._sql_management_client_enums import QueryTimeGrainType +from ._sql_management_client_enums import ReadOnlyEndpointFailoverPolicy +from ._sql_management_client_enums import ReadWriteEndpointFailoverPolicy +from ._sql_management_client_enums import RecommendedActionCurrentState +from ._sql_management_client_enums import RecommendedActionInitiatedBy +from ._sql_management_client_enums import RecommendedSensitivityLabelUpdateKind +from ._sql_management_client_enums import ReplicaType +from ._sql_management_client_enums import ReplicationLinkType +from ._sql_management_client_enums import ReplicationMode +from ._sql_management_client_enums import ReplicationRole +from ._sql_management_client_enums import ReplicationState +from ._sql_management_client_enums import RestoreDetailsName +from ._sql_management_client_enums import RestorePointType +from ._sql_management_client_enums import SampleName +from ._sql_management_client_enums import SecondaryType +from ._sql_management_client_enums import SecurityAlertPolicyName +from ._sql_management_client_enums import SecurityAlertPolicyState +from ._sql_management_client_enums import SecurityAlertsPolicyState +from ._sql_management_client_enums import SecurityEventType +from ._sql_management_client_enums import SensitivityLabelRank +from ._sql_management_client_enums import SensitivityLabelSource +from ._sql_management_client_enums import SensitivityLabelUpdateKind +from ._sql_management_client_enums import ServerConnectionType +from ._sql_management_client_enums import ServerKeyType +from ._sql_management_client_enums import ServerNetworkAccessFlag +from ._sql_management_client_enums import ServerTrustGroupPropertiesTrustScopesItem +from ._sql_management_client_enums import ServerWorkspaceFeature +from ._sql_management_client_enums import ServiceObjectiveName +from ._sql_management_client_enums import ServicePrincipalType +from ._sql_management_client_enums import ShortTermRetentionPolicyName +from ._sql_management_client_enums import SqlAgentConfigurationPropertiesState +from ._sql_management_client_enums import StorageCapabilityStorageAccountType +from ._sql_management_client_enums import StorageKeyType +from ._sql_management_client_enums import SyncAgentState +from ._sql_management_client_enums import SyncConflictResolutionPolicy +from ._sql_management_client_enums import SyncDirection +from ._sql_management_client_enums import SyncGroupLogType +from ._sql_management_client_enums import SyncGroupState +from ._sql_management_client_enums import SyncGroupsType +from ._sql_management_client_enums import SyncMemberDbType +from ._sql_management_client_enums import SyncMemberState +from ._sql_management_client_enums import TableTemporalType +from ._sql_management_client_enums import TransparentDataEncryptionName +from ._sql_management_client_enums import TransparentDataEncryptionState +from ._sql_management_client_enums import UnitDefinitionType +from ._sql_management_client_enums import UnitType +from ._sql_management_client_enums import UpsertManagedServerOperationStepStatus +from ._sql_management_client_enums import VirtualNetworkRuleState +from ._sql_management_client_enums import VulnerabilityAssessmentName +from ._sql_management_client_enums import VulnerabilityAssessmentPolicyBaselineName +from ._sql_management_client_enums import VulnerabilityAssessmentScanState +from ._sql_management_client_enums import VulnerabilityAssessmentScanTriggerType from ._patch import __all__ as _patch_all from ._patch import * # type: ignore # pylint: disable=unused-wildcard-import from ._patch import patch_sdk as _patch_sdk + __all__ = [ - 'AdministratorListResult', - 'Advisor', - 'AutoPauseDelayTimeRange', - 'AutomaticTuningOptions', - 'AutomaticTuningServerOptions', - 'AzureADOnlyAuthListResult', - 'BackupShortTermRetentionPolicy', - 'BackupShortTermRetentionPolicyListResult', - 'CheckNameAvailabilityRequest', - 'CheckNameAvailabilityResponse', - 'CompleteDatabaseRestoreDefinition', - 'CopyLongTermRetentionBackupParameters', - 'CreateDatabaseRestorePointDefinition', - 'DataMaskingPolicy', - 'DataMaskingRule', - 'DataMaskingRuleListResult', - 'DataWarehouseUserActivities', - 'DataWarehouseUserActivitiesListResult', - 'Database', - 'DatabaseAdvancedThreatProtection', - 'DatabaseAdvancedThreatProtectionListResult', - 'DatabaseAutomaticTuning', - 'DatabaseBlobAuditingPolicy', - 'DatabaseBlobAuditingPolicyListResult', - 'DatabaseColumn', - 'DatabaseColumnListResult', - 'DatabaseExtensions', - 'DatabaseIdentity', - 'DatabaseListResult', - 'DatabaseOperation', - 'DatabaseOperationListResult', - 'DatabaseSchema', - 'DatabaseSchemaListResult', - 'DatabaseSecurityAlertListResult', - 'DatabaseSecurityAlertPolicy', - 'DatabaseTable', - 'DatabaseTableListResult', - 'DatabaseUpdate', - 'DatabaseUsage', - 'DatabaseUsageListResult', - 'DatabaseUserIdentity', - 'DatabaseVulnerabilityAssessment', - 'DatabaseVulnerabilityAssessmentListResult', - 'DatabaseVulnerabilityAssessmentRuleBaseline', - 'DatabaseVulnerabilityAssessmentRuleBaselineItem', - 'DatabaseVulnerabilityAssessmentScansExport', - 'DeletedServer', - 'DeletedServerListResult', - 'DistributedAvailabilityGroup', - 'DistributedAvailabilityGroupsListResult', - 'EditionCapability', - 'ElasticPool', - 'ElasticPoolActivity', - 'ElasticPoolActivityListResult', - 'ElasticPoolDatabaseActivity', - 'ElasticPoolDatabaseActivityListResult', - 'ElasticPoolEditionCapability', - 'ElasticPoolListResult', - 'ElasticPoolOperation', - 'ElasticPoolOperationListResult', - 'ElasticPoolPerDatabaseMaxPerformanceLevelCapability', - 'ElasticPoolPerDatabaseMinPerformanceLevelCapability', - 'ElasticPoolPerDatabaseSettings', - 'ElasticPoolPerformanceLevelCapability', - 'ElasticPoolUpdate', - 'EncryptionProtector', - 'EncryptionProtectorListResult', - 'EndpointCertificate', - 'EndpointCertificateListResult', - 'ExportDatabaseDefinition', - 'ExtendedDatabaseBlobAuditingPolicy', - 'ExtendedDatabaseBlobAuditingPolicyListResult', - 'ExtendedServerBlobAuditingPolicy', - 'ExtendedServerBlobAuditingPolicyListResult', - 'FailoverGroup', - 'FailoverGroupListResult', - 'FailoverGroupReadOnlyEndpoint', - 'FailoverGroupReadWriteEndpoint', - 'FailoverGroupUpdate', - 'FirewallRule', - 'FirewallRuleList', - 'FirewallRuleListResult', - 'GeoBackupPolicy', - 'GeoBackupPolicyListResult', - 'IPv6FirewallRule', - 'IPv6FirewallRuleListResult', - 'ImportExistingDatabaseDefinition', - 'ImportExportExtensionsOperationListResult', - 'ImportExportExtensionsOperationResult', - 'ImportExportOperationResult', - 'ImportNewDatabaseDefinition', - 'InstanceFailoverGroup', - 'InstanceFailoverGroupListResult', - 'InstanceFailoverGroupReadOnlyEndpoint', - 'InstanceFailoverGroupReadWriteEndpoint', - 'InstancePool', - 'InstancePoolEditionCapability', - 'InstancePoolFamilyCapability', - 'InstancePoolListResult', - 'InstancePoolUpdate', - 'InstancePoolVcoresCapability', - 'Job', - 'JobAgent', - 'JobAgentListResult', - 'JobAgentUpdate', - 'JobCredential', - 'JobCredentialListResult', - 'JobExecution', - 'JobExecutionListResult', - 'JobExecutionTarget', - 'JobListResult', - 'JobSchedule', - 'JobStep', - 'JobStepAction', - 'JobStepExecutionOptions', - 'JobStepListResult', - 'JobStepOutput', - 'JobTarget', - 'JobTargetGroup', - 'JobTargetGroupListResult', - 'JobVersion', - 'JobVersionListResult', - 'LedgerDigestUploads', - 'LedgerDigestUploadsListResult', - 'LicenseTypeCapability', - 'LocationCapabilities', - 'LogSizeCapability', - 'LogicalDatabaseTransparentDataEncryption', - 'LogicalDatabaseTransparentDataEncryptionListResult', - 'LogicalServerAdvancedThreatProtectionListResult', - 'LogicalServerSecurityAlertPolicyListResult', - 'LongTermRetentionBackup', - 'LongTermRetentionBackupListResult', - 'LongTermRetentionBackupOperationResult', - 'LongTermRetentionPolicy', - 'LongTermRetentionPolicyListResult', - 'MaintenanceConfigurationCapability', - 'MaintenanceWindowOptions', - 'MaintenanceWindowTimeRange', - 'MaintenanceWindows', - 'ManagedBackupShortTermRetentionPolicy', - 'ManagedBackupShortTermRetentionPolicyListResult', - 'ManagedDatabase', - 'ManagedDatabaseListResult', - 'ManagedDatabaseRestoreDetailsResult', - 'ManagedDatabaseSecurityAlertPolicy', - 'ManagedDatabaseSecurityAlertPolicyListResult', - 'ManagedDatabaseUpdate', - 'ManagedInstance', - 'ManagedInstanceAdministrator', - 'ManagedInstanceAdministratorListResult', - 'ManagedInstanceAzureADOnlyAuthListResult', - 'ManagedInstanceAzureADOnlyAuthentication', - 'ManagedInstanceEditionCapability', - 'ManagedInstanceEncryptionProtector', - 'ManagedInstanceEncryptionProtectorListResult', - 'ManagedInstanceExternalAdministrator', - 'ManagedInstanceFamilyCapability', - 'ManagedInstanceKey', - 'ManagedInstanceKeyListResult', - 'ManagedInstanceListResult', - 'ManagedInstanceLongTermRetentionBackup', - 'ManagedInstanceLongTermRetentionBackupListResult', - 'ManagedInstanceLongTermRetentionPolicy', - 'ManagedInstanceLongTermRetentionPolicyListResult', - 'ManagedInstanceMaintenanceConfigurationCapability', - 'ManagedInstanceOperation', - 'ManagedInstanceOperationListResult', - 'ManagedInstanceOperationParametersPair', - 'ManagedInstanceOperationSteps', - 'ManagedInstancePairInfo', - 'ManagedInstancePecProperty', - 'ManagedInstancePrivateEndpointConnection', - 'ManagedInstancePrivateEndpointConnectionListResult', - 'ManagedInstancePrivateEndpointConnectionProperties', - 'ManagedInstancePrivateEndpointProperty', - 'ManagedInstancePrivateLink', - 'ManagedInstancePrivateLinkListResult', - 'ManagedInstancePrivateLinkProperties', - 'ManagedInstancePrivateLinkServiceConnectionStateProperty', - 'ManagedInstanceQuery', - 'ManagedInstanceQueryStatistics', - 'ManagedInstanceUpdate', - 'ManagedInstanceVcoresCapability', - 'ManagedInstanceVersionCapability', - 'ManagedInstanceVulnerabilityAssessment', - 'ManagedInstanceVulnerabilityAssessmentListResult', - 'ManagedServerDnsAlias', - 'ManagedServerDnsAliasAcquisition', - 'ManagedServerDnsAliasCreation', - 'ManagedServerDnsAliasListResult', - 'ManagedServerSecurityAlertPolicy', - 'ManagedServerSecurityAlertPolicyListResult', - 'ManagedTransparentDataEncryption', - 'ManagedTransparentDataEncryptionListResult', - 'MaxSizeCapability', - 'MaxSizeRangeCapability', - 'Metric', - 'MetricAvailability', - 'MetricDefinition', - 'MetricDefinitionListResult', - 'MetricListResult', - 'MetricName', - 'MetricValue', - 'MinCapacityCapability', - 'Name', - 'NetworkIsolationSettings', - 'Operation', - 'OperationDisplay', - 'OperationImpact', - 'OperationListResult', - 'OutboundFirewallRule', - 'OutboundFirewallRuleListResult', - 'PartnerInfo', - 'PartnerRegionInfo', - 'PerformanceLevelCapability', - 'PrivateEndpointConnection', - 'PrivateEndpointConnectionListResult', - 'PrivateEndpointConnectionProperties', - 'PrivateEndpointConnectionRequestStatus', - 'PrivateEndpointProperty', - 'PrivateLinkResource', - 'PrivateLinkResourceListResult', - 'PrivateLinkResourceProperties', - 'PrivateLinkServiceConnectionStateProperty', - 'ProxyResource', - 'ProxyResourceWithWritableName', - 'QueryMetricInterval', - 'QueryMetricProperties', - 'QueryStatistics', - 'QueryStatisticsProperties', - 'ReadScaleCapability', - 'RecommendedAction', - 'RecommendedActionErrorInfo', - 'RecommendedActionImpactRecord', - 'RecommendedActionImplementationInfo', - 'RecommendedActionMetricInfo', - 'RecommendedActionStateInfo', - 'RecommendedSensitivityLabelUpdate', - 'RecommendedSensitivityLabelUpdateList', - 'RecoverableDatabase', - 'RecoverableDatabaseListResult', - 'RecoverableManagedDatabase', - 'RecoverableManagedDatabaseListResult', - 'ReplicationLink', - 'ReplicationLinkListResult', - 'Resource', - 'ResourceIdentity', - 'ResourceMoveDefinition', - 'ResourceWithWritableName', - 'RestorableDroppedDatabase', - 'RestorableDroppedDatabaseListResult', - 'RestorableDroppedManagedDatabase', - 'RestorableDroppedManagedDatabaseListResult', - 'RestorePoint', - 'RestorePointListResult', - 'SecurityEvent', - 'SecurityEventCollection', - 'SecurityEventSqlInjectionAdditionalProperties', - 'SecurityEventsFilterParameters', - 'SensitivityLabel', - 'SensitivityLabelListResult', - 'SensitivityLabelUpdate', - 'SensitivityLabelUpdateList', - 'Server', - 'ServerAdvancedThreatProtection', - 'ServerAutomaticTuning', - 'ServerAzureADAdministrator', - 'ServerAzureADOnlyAuthentication', - 'ServerBlobAuditingPolicy', - 'ServerBlobAuditingPolicyListResult', - 'ServerCommunicationLink', - 'ServerCommunicationLinkListResult', - 'ServerConnectionPolicy', - 'ServerConnectionPolicyListResult', - 'ServerDevOpsAuditSettingsListResult', - 'ServerDevOpsAuditingSettings', - 'ServerDnsAlias', - 'ServerDnsAliasAcquisition', - 'ServerDnsAliasListResult', - 'ServerExternalAdministrator', - 'ServerInfo', - 'ServerKey', - 'ServerKeyListResult', - 'ServerListResult', - 'ServerOperation', - 'ServerOperationListResult', - 'ServerPrivateEndpointConnection', - 'ServerSecurityAlertPolicy', - 'ServerTrustCertificate', - 'ServerTrustCertificatesListResult', - 'ServerTrustGroup', - 'ServerTrustGroupListResult', - 'ServerUpdate', - 'ServerUsage', - 'ServerUsageListResult', - 'ServerVersionCapability', - 'ServerVulnerabilityAssessment', - 'ServerVulnerabilityAssessmentListResult', - 'ServiceObjective', - 'ServiceObjectiveCapability', - 'ServiceObjectiveListResult', - 'ServicePrincipal', - 'Sku', - 'SloUsageMetric', - 'SqlAgentConfiguration', - 'StorageCapability', - 'SubscriptionUsage', - 'SubscriptionUsageListResult', - 'SyncAgent', - 'SyncAgentKeyProperties', - 'SyncAgentLinkedDatabase', - 'SyncAgentLinkedDatabaseListResult', - 'SyncAgentListResult', - 'SyncDatabaseIdListResult', - 'SyncDatabaseIdProperties', - 'SyncFullSchemaProperties', - 'SyncFullSchemaPropertiesListResult', - 'SyncFullSchemaTable', - 'SyncFullSchemaTableColumn', - 'SyncGroup', - 'SyncGroupListResult', - 'SyncGroupLogListResult', - 'SyncGroupLogProperties', - 'SyncGroupSchema', - 'SyncGroupSchemaTable', - 'SyncGroupSchemaTableColumn', - 'SyncMember', - 'SyncMemberListResult', - 'SystemData', - 'TdeCertificate', - 'TimeZone', - 'TimeZoneListResult', - 'TopQueries', - 'TopQueriesListResult', - 'TrackedResource', - 'UpdateLongTermRetentionBackupParameters', - 'UpdateManagedInstanceDnsServersOperation', - 'UpsertManagedServerOperationParameters', - 'UpsertManagedServerOperationStep', - 'Usage', - 'UsageListResult', - 'UserIdentity', - 'VirtualCluster', - 'VirtualClusterListResult', - 'VirtualClusterUpdate', - 'VirtualNetworkRule', - 'VirtualNetworkRuleListResult', - 'VulnerabilityAssessmentRecurringScansProperties', - 'VulnerabilityAssessmentScanError', - 'VulnerabilityAssessmentScanRecord', - 'VulnerabilityAssessmentScanRecordListResult', - 'WorkloadClassifier', - 'WorkloadClassifierListResult', - 'WorkloadGroup', - 'WorkloadGroupListResult', - 'AdministratorName', - 'AdministratorType', - 'AdvancedThreatProtectionName', - 'AdvancedThreatProtectionState', - 'AdvisorStatus', - 'AggregationFunctionType', - 'AuthenticationName', - 'AutoExecuteStatus', - 'AutoExecuteStatusInheritedFrom', - 'AutomaticTuningDisabledReason', - 'AutomaticTuningMode', - 'AutomaticTuningOptionModeActual', - 'AutomaticTuningOptionModeDesired', - 'AutomaticTuningServerMode', - 'AutomaticTuningServerReason', - 'BackupStorageRedundancy', - 'BlobAuditingPolicyState', - 'CapabilityGroup', - 'CapabilityStatus', - 'CatalogCollationType', - 'CheckNameAvailabilityReason', - 'ColumnDataType', - 'ConnectionPolicyName', - 'CreateMode', - 'CreatedByType', - 'DataMaskingFunction', - 'DataMaskingRuleState', - 'DataMaskingState', - 'DataWarehouseUserActivityName', - 'DatabaseIdentityType', - 'DatabaseLicenseType', - 'DatabaseReadScale', - 'DatabaseState', - 'DatabaseStatus', - 'DayOfWeek', - 'DiffBackupIntervalInHours', - 'DnsRefreshConfigurationPropertiesStatus', - 'ElasticPoolLicenseType', - 'ElasticPoolState', - 'EncryptionProtectorName', - 'FailoverGroupReplicationRole', - 'GeoBackupPolicyName', - 'GeoBackupPolicyState', - 'IdentityType', - 'ImplementationMethod', - 'InstanceFailoverGroupReplicationRole', - 'InstancePoolLicenseType', - 'IsRetryable', - 'JobAgentState', - 'JobExecutionLifecycle', - 'JobScheduleType', - 'JobStepActionSource', - 'JobStepActionType', - 'JobStepOutputType', - 'JobTargetGroupMembershipType', - 'JobTargetType', - 'LedgerDigestUploadsName', - 'LedgerDigestUploadsState', - 'LogSizeUnit', - 'LongTermRetentionPolicyName', - 'ManagedDatabaseCreateMode', - 'ManagedDatabaseStatus', - 'ManagedInstanceAdministratorType', - 'ManagedInstanceLicenseType', - 'ManagedInstanceLongTermRetentionPolicyName', - 'ManagedInstancePropertiesProvisioningState', - 'ManagedInstanceProxyOverride', - 'ManagedServerCreateMode', - 'ManagedShortTermRetentionPolicyName', - 'ManagementOperationState', - 'MaxSizeUnit', - 'MetricType', - 'OperationMode', - 'OperationOrigin', - 'PauseDelayTimeUnit', - 'PerformanceLevelUnit', - 'PrimaryAggregationType', - 'PrincipalType', - 'PrivateEndpointProvisioningState', - 'PrivateLinkServiceConnectionStateActionsRequire', - 'PrivateLinkServiceConnectionStateStatus', - 'ProvisioningState', - 'QueryMetricUnitType', - 'QueryTimeGrainType', - 'ReadOnlyEndpointFailoverPolicy', - 'ReadWriteEndpointFailoverPolicy', - 'RecommendedActionCurrentState', - 'RecommendedActionInitiatedBy', - 'RecommendedSensitivityLabelUpdateKind', - 'ReplicaType', - 'ReplicationLinkType', - 'ReplicationMode', - 'ReplicationRole', - 'ReplicationState', - 'RestoreDetailsName', - 'RestorePointType', - 'SampleName', - 'SecondaryType', - 'SecurityAlertPolicyName', - 'SecurityAlertPolicyState', - 'SecurityAlertsPolicyState', - 'SecurityEventType', - 'SensitivityLabelRank', - 'SensitivityLabelSource', - 'SensitivityLabelUpdateKind', - 'ServerConnectionType', - 'ServerKeyType', - 'ServerNetworkAccessFlag', - 'ServerTrustGroupPropertiesTrustScopesItem', - 'ServerWorkspaceFeature', - 'ServiceObjectiveName', - 'ServicePrincipalType', - 'ShortTermRetentionPolicyName', - 'SqlAgentConfigurationPropertiesState', - 'StorageCapabilityStorageAccountType', - 'StorageKeyType', - 'SyncAgentState', - 'SyncConflictResolutionPolicy', - 'SyncDirection', - 'SyncGroupLogType', - 'SyncGroupState', - 'SyncGroupsType', - 'SyncMemberDbType', - 'SyncMemberState', - 'TableTemporalType', - 'TransparentDataEncryptionName', - 'TransparentDataEncryptionState', - 'UnitDefinitionType', - 'UnitType', - 'UpsertManagedServerOperationStepStatus', - 'VirtualNetworkRuleState', - 'VulnerabilityAssessmentName', - 'VulnerabilityAssessmentPolicyBaselineName', - 'VulnerabilityAssessmentScanState', - 'VulnerabilityAssessmentScanTriggerType', + "AdministratorListResult", + "Advisor", + "AutoPauseDelayTimeRange", + "AutomaticTuningOptions", + "AutomaticTuningServerOptions", + "AzureADOnlyAuthListResult", + "BackupShortTermRetentionPolicy", + "BackupShortTermRetentionPolicyListResult", + "CheckNameAvailabilityRequest", + "CheckNameAvailabilityResponse", + "CompleteDatabaseRestoreDefinition", + "CopyLongTermRetentionBackupParameters", + "CreateDatabaseRestorePointDefinition", + "DataMaskingPolicy", + "DataMaskingRule", + "DataMaskingRuleListResult", + "DataWarehouseUserActivities", + "DataWarehouseUserActivitiesListResult", + "Database", + "DatabaseAdvancedThreatProtection", + "DatabaseAdvancedThreatProtectionListResult", + "DatabaseAutomaticTuning", + "DatabaseBlobAuditingPolicy", + "DatabaseBlobAuditingPolicyListResult", + "DatabaseColumn", + "DatabaseColumnListResult", + "DatabaseExtensions", + "DatabaseIdentity", + "DatabaseListResult", + "DatabaseOperation", + "DatabaseOperationListResult", + "DatabaseSchema", + "DatabaseSchemaListResult", + "DatabaseSecurityAlertListResult", + "DatabaseSecurityAlertPolicy", + "DatabaseTable", + "DatabaseTableListResult", + "DatabaseUpdate", + "DatabaseUsage", + "DatabaseUsageListResult", + "DatabaseUserIdentity", + "DatabaseVulnerabilityAssessment", + "DatabaseVulnerabilityAssessmentListResult", + "DatabaseVulnerabilityAssessmentRuleBaseline", + "DatabaseVulnerabilityAssessmentRuleBaselineItem", + "DatabaseVulnerabilityAssessmentScansExport", + "DeletedServer", + "DeletedServerListResult", + "DistributedAvailabilityGroup", + "DistributedAvailabilityGroupsListResult", + "EditionCapability", + "ElasticPool", + "ElasticPoolActivity", + "ElasticPoolActivityListResult", + "ElasticPoolDatabaseActivity", + "ElasticPoolDatabaseActivityListResult", + "ElasticPoolEditionCapability", + "ElasticPoolListResult", + "ElasticPoolOperation", + "ElasticPoolOperationListResult", + "ElasticPoolPerDatabaseMaxPerformanceLevelCapability", + "ElasticPoolPerDatabaseMinPerformanceLevelCapability", + "ElasticPoolPerDatabaseSettings", + "ElasticPoolPerformanceLevelCapability", + "ElasticPoolUpdate", + "EncryptionProtector", + "EncryptionProtectorListResult", + "EndpointCertificate", + "EndpointCertificateListResult", + "ExportDatabaseDefinition", + "ExtendedDatabaseBlobAuditingPolicy", + "ExtendedDatabaseBlobAuditingPolicyListResult", + "ExtendedServerBlobAuditingPolicy", + "ExtendedServerBlobAuditingPolicyListResult", + "FailoverGroup", + "FailoverGroupListResult", + "FailoverGroupReadOnlyEndpoint", + "FailoverGroupReadWriteEndpoint", + "FailoverGroupUpdate", + "FirewallRule", + "FirewallRuleList", + "FirewallRuleListResult", + "GeoBackupPolicy", + "GeoBackupPolicyListResult", + "IPv6FirewallRule", + "IPv6FirewallRuleListResult", + "ImportExistingDatabaseDefinition", + "ImportExportExtensionsOperationListResult", + "ImportExportExtensionsOperationResult", + "ImportExportOperationResult", + "ImportNewDatabaseDefinition", + "InstanceFailoverGroup", + "InstanceFailoverGroupListResult", + "InstanceFailoverGroupReadOnlyEndpoint", + "InstanceFailoverGroupReadWriteEndpoint", + "InstancePool", + "InstancePoolEditionCapability", + "InstancePoolFamilyCapability", + "InstancePoolListResult", + "InstancePoolUpdate", + "InstancePoolVcoresCapability", + "Job", + "JobAgent", + "JobAgentListResult", + "JobAgentUpdate", + "JobCredential", + "JobCredentialListResult", + "JobExecution", + "JobExecutionListResult", + "JobExecutionTarget", + "JobListResult", + "JobSchedule", + "JobStep", + "JobStepAction", + "JobStepExecutionOptions", + "JobStepListResult", + "JobStepOutput", + "JobTarget", + "JobTargetGroup", + "JobTargetGroupListResult", + "JobVersion", + "JobVersionListResult", + "LedgerDigestUploads", + "LedgerDigestUploadsListResult", + "LicenseTypeCapability", + "LocationCapabilities", + "LogSizeCapability", + "LogicalDatabaseTransparentDataEncryption", + "LogicalDatabaseTransparentDataEncryptionListResult", + "LogicalServerAdvancedThreatProtectionListResult", + "LogicalServerSecurityAlertPolicyListResult", + "LongTermRetentionBackup", + "LongTermRetentionBackupListResult", + "LongTermRetentionBackupOperationResult", + "LongTermRetentionPolicy", + "LongTermRetentionPolicyListResult", + "MaintenanceConfigurationCapability", + "MaintenanceWindowOptions", + "MaintenanceWindowTimeRange", + "MaintenanceWindows", + "ManagedBackupShortTermRetentionPolicy", + "ManagedBackupShortTermRetentionPolicyListResult", + "ManagedDatabase", + "ManagedDatabaseAdvancedThreatProtection", + "ManagedDatabaseAdvancedThreatProtectionListResult", + "ManagedDatabaseListResult", + "ManagedDatabaseMoveDefinition", + "ManagedDatabaseRestoreDetailsBackupSetProperties", + "ManagedDatabaseRestoreDetailsResult", + "ManagedDatabaseRestoreDetailsUnrestorableFileProperties", + "ManagedDatabaseSecurityAlertPolicy", + "ManagedDatabaseSecurityAlertPolicyListResult", + "ManagedDatabaseStartMoveDefinition", + "ManagedDatabaseUpdate", + "ManagedInstance", + "ManagedInstanceAdministrator", + "ManagedInstanceAdministratorListResult", + "ManagedInstanceAdvancedThreatProtection", + "ManagedInstanceAdvancedThreatProtectionListResult", + "ManagedInstanceAzureADOnlyAuthListResult", + "ManagedInstanceAzureADOnlyAuthentication", + "ManagedInstanceDtc", + "ManagedInstanceDtcListResult", + "ManagedInstanceDtcSecuritySettings", + "ManagedInstanceDtcTransactionManagerCommunicationSettings", + "ManagedInstanceEditionCapability", + "ManagedInstanceEncryptionProtector", + "ManagedInstanceEncryptionProtectorListResult", + "ManagedInstanceExternalAdministrator", + "ManagedInstanceFamilyCapability", + "ManagedInstanceKey", + "ManagedInstanceKeyListResult", + "ManagedInstanceListResult", + "ManagedInstanceLongTermRetentionBackup", + "ManagedInstanceLongTermRetentionBackupListResult", + "ManagedInstanceLongTermRetentionPolicy", + "ManagedInstanceLongTermRetentionPolicyListResult", + "ManagedInstanceMaintenanceConfigurationCapability", + "ManagedInstanceOperation", + "ManagedInstanceOperationListResult", + "ManagedInstanceOperationParametersPair", + "ManagedInstanceOperationSteps", + "ManagedInstancePairInfo", + "ManagedInstancePecProperty", + "ManagedInstancePrivateEndpointConnection", + "ManagedInstancePrivateEndpointConnectionListResult", + "ManagedInstancePrivateEndpointConnectionProperties", + "ManagedInstancePrivateEndpointProperty", + "ManagedInstancePrivateLink", + "ManagedInstancePrivateLinkListResult", + "ManagedInstancePrivateLinkProperties", + "ManagedInstancePrivateLinkServiceConnectionStateProperty", + "ManagedInstanceQuery", + "ManagedInstanceQueryStatistics", + "ManagedInstanceUpdate", + "ManagedInstanceVcoresCapability", + "ManagedInstanceVersionCapability", + "ManagedInstanceVulnerabilityAssessment", + "ManagedInstanceVulnerabilityAssessmentListResult", + "ManagedServerDnsAlias", + "ManagedServerDnsAliasAcquisition", + "ManagedServerDnsAliasCreation", + "ManagedServerDnsAliasListResult", + "ManagedServerSecurityAlertPolicy", + "ManagedServerSecurityAlertPolicyListResult", + "ManagedTransparentDataEncryption", + "ManagedTransparentDataEncryptionListResult", + "MaxSizeCapability", + "MaxSizeRangeCapability", + "Metric", + "MetricAvailability", + "MetricDefinition", + "MetricDefinitionListResult", + "MetricListResult", + "MetricName", + "MetricValue", + "MinCapacityCapability", + "Name", + "NetworkIsolationSettings", + "Operation", + "OperationDisplay", + "OperationImpact", + "OperationListResult", + "OutboundFirewallRule", + "OutboundFirewallRuleListResult", + "PartnerInfo", + "PartnerRegionInfo", + "PerformanceLevelCapability", + "PrivateEndpointConnection", + "PrivateEndpointConnectionListResult", + "PrivateEndpointConnectionProperties", + "PrivateEndpointConnectionRequestStatus", + "PrivateEndpointProperty", + "PrivateLinkResource", + "PrivateLinkResourceListResult", + "PrivateLinkResourceProperties", + "PrivateLinkServiceConnectionStateProperty", + "ProxyResource", + "ProxyResourceWithWritableName", + "QueryMetricInterval", + "QueryMetricProperties", + "QueryStatistics", + "QueryStatisticsProperties", + "ReadScaleCapability", + "RecommendedAction", + "RecommendedActionErrorInfo", + "RecommendedActionImpactRecord", + "RecommendedActionImplementationInfo", + "RecommendedActionMetricInfo", + "RecommendedActionStateInfo", + "RecommendedSensitivityLabelUpdate", + "RecommendedSensitivityLabelUpdateList", + "RecoverableDatabase", + "RecoverableDatabaseListResult", + "RecoverableManagedDatabase", + "RecoverableManagedDatabaseListResult", + "ReplicationLink", + "ReplicationLinkListResult", + "Resource", + "ResourceIdentity", + "ResourceMoveDefinition", + "ResourceWithWritableName", + "RestorableDroppedDatabase", + "RestorableDroppedDatabaseListResult", + "RestorableDroppedManagedDatabase", + "RestorableDroppedManagedDatabaseListResult", + "RestorePoint", + "RestorePointListResult", + "SecurityEvent", + "SecurityEventCollection", + "SecurityEventSqlInjectionAdditionalProperties", + "SecurityEventsFilterParameters", + "SensitivityLabel", + "SensitivityLabelListResult", + "SensitivityLabelUpdate", + "SensitivityLabelUpdateList", + "Server", + "ServerAdvancedThreatProtection", + "ServerAutomaticTuning", + "ServerAzureADAdministrator", + "ServerAzureADOnlyAuthentication", + "ServerBlobAuditingPolicy", + "ServerBlobAuditingPolicyListResult", + "ServerCommunicationLink", + "ServerCommunicationLinkListResult", + "ServerConnectionPolicy", + "ServerConnectionPolicyListResult", + "ServerDevOpsAuditSettingsListResult", + "ServerDevOpsAuditingSettings", + "ServerDnsAlias", + "ServerDnsAliasAcquisition", + "ServerDnsAliasListResult", + "ServerExternalAdministrator", + "ServerInfo", + "ServerKey", + "ServerKeyListResult", + "ServerListResult", + "ServerOperation", + "ServerOperationListResult", + "ServerPrivateEndpointConnection", + "ServerSecurityAlertPolicy", + "ServerTrustCertificate", + "ServerTrustCertificatesListResult", + "ServerTrustGroup", + "ServerTrustGroupListResult", + "ServerUpdate", + "ServerUsage", + "ServerUsageListResult", + "ServerVersionCapability", + "ServerVulnerabilityAssessment", + "ServerVulnerabilityAssessmentListResult", + "ServiceObjective", + "ServiceObjectiveCapability", + "ServiceObjectiveListResult", + "ServicePrincipal", + "Sku", + "SloUsageMetric", + "SqlAgentConfiguration", + "StorageCapability", + "SubscriptionUsage", + "SubscriptionUsageListResult", + "SyncAgent", + "SyncAgentKeyProperties", + "SyncAgentLinkedDatabase", + "SyncAgentLinkedDatabaseListResult", + "SyncAgentListResult", + "SyncDatabaseIdListResult", + "SyncDatabaseIdProperties", + "SyncFullSchemaProperties", + "SyncFullSchemaPropertiesListResult", + "SyncFullSchemaTable", + "SyncFullSchemaTableColumn", + "SyncGroup", + "SyncGroupListResult", + "SyncGroupLogListResult", + "SyncGroupLogProperties", + "SyncGroupSchema", + "SyncGroupSchemaTable", + "SyncGroupSchemaTableColumn", + "SyncMember", + "SyncMemberListResult", + "SystemData", + "TdeCertificate", + "TimeZone", + "TimeZoneListResult", + "TopQueries", + "TopQueriesListResult", + "TrackedResource", + "UpdateLongTermRetentionBackupParameters", + "UpdateManagedInstanceDnsServersOperation", + "UpsertManagedServerOperationParameters", + "UpsertManagedServerOperationStep", + "Usage", + "UsageListResult", + "UserIdentity", + "VirtualCluster", + "VirtualClusterListResult", + "VirtualClusterUpdate", + "VirtualNetworkRule", + "VirtualNetworkRuleListResult", + "VulnerabilityAssessmentRecurringScansProperties", + "VulnerabilityAssessmentScanError", + "VulnerabilityAssessmentScanRecord", + "VulnerabilityAssessmentScanRecordListResult", + "WorkloadClassifier", + "WorkloadClassifierListResult", + "WorkloadGroup", + "WorkloadGroupListResult", + "AdministratorName", + "AdministratorType", + "AdvancedThreatProtectionName", + "AdvancedThreatProtectionState", + "AdvisorStatus", + "AggregationFunctionType", + "AuthenticationName", + "AutoExecuteStatus", + "AutoExecuteStatusInheritedFrom", + "AutomaticTuningDisabledReason", + "AutomaticTuningMode", + "AutomaticTuningOptionModeActual", + "AutomaticTuningOptionModeDesired", + "AutomaticTuningServerMode", + "AutomaticTuningServerReason", + "BackupStorageRedundancy", + "BlobAuditingPolicyState", + "CapabilityGroup", + "CapabilityStatus", + "CatalogCollationType", + "CheckNameAvailabilityReason", + "ColumnDataType", + "ConnectionPolicyName", + "CreateMode", + "CreatedByType", + "DataMaskingFunction", + "DataMaskingRuleState", + "DataMaskingState", + "DataWarehouseUserActivityName", + "DatabaseIdentityType", + "DatabaseLicenseType", + "DatabaseReadScale", + "DatabaseState", + "DatabaseStatus", + "DayOfWeek", + "DiffBackupIntervalInHours", + "DnsRefreshConfigurationPropertiesStatus", + "DtcName", + "ElasticPoolLicenseType", + "ElasticPoolState", + "EncryptionProtectorName", + "FailoverGroupReplicationRole", + "GeoBackupPolicyName", + "GeoBackupPolicyState", + "IdentityType", + "ImplementationMethod", + "InstanceFailoverGroupReplicationRole", + "InstancePoolLicenseType", + "IsRetryable", + "JobAgentState", + "JobExecutionLifecycle", + "JobScheduleType", + "JobStepActionSource", + "JobStepActionType", + "JobStepOutputType", + "JobTargetGroupMembershipType", + "JobTargetType", + "LedgerDigestUploadsName", + "LedgerDigestUploadsState", + "LogSizeUnit", + "LongTermRetentionPolicyName", + "ManagedDatabaseCreateMode", + "ManagedDatabaseStatus", + "ManagedInstanceAdministratorType", + "ManagedInstanceLicenseType", + "ManagedInstanceLongTermRetentionPolicyName", + "ManagedInstancePropertiesProvisioningState", + "ManagedInstanceProxyOverride", + "ManagedServerCreateMode", + "ManagedShortTermRetentionPolicyName", + "ManagementOperationState", + "MaxSizeUnit", + "MetricType", + "MoveOperationMode", + "OperationMode", + "OperationOrigin", + "PauseDelayTimeUnit", + "PerformanceLevelUnit", + "PrimaryAggregationType", + "PrincipalType", + "PrivateEndpointProvisioningState", + "PrivateLinkServiceConnectionStateActionsRequire", + "PrivateLinkServiceConnectionStateStatus", + "ProvisioningState", + "QueryMetricUnitType", + "QueryTimeGrainType", + "ReadOnlyEndpointFailoverPolicy", + "ReadWriteEndpointFailoverPolicy", + "RecommendedActionCurrentState", + "RecommendedActionInitiatedBy", + "RecommendedSensitivityLabelUpdateKind", + "ReplicaType", + "ReplicationLinkType", + "ReplicationMode", + "ReplicationRole", + "ReplicationState", + "RestoreDetailsName", + "RestorePointType", + "SampleName", + "SecondaryType", + "SecurityAlertPolicyName", + "SecurityAlertPolicyState", + "SecurityAlertsPolicyState", + "SecurityEventType", + "SensitivityLabelRank", + "SensitivityLabelSource", + "SensitivityLabelUpdateKind", + "ServerConnectionType", + "ServerKeyType", + "ServerNetworkAccessFlag", + "ServerTrustGroupPropertiesTrustScopesItem", + "ServerWorkspaceFeature", + "ServiceObjectiveName", + "ServicePrincipalType", + "ShortTermRetentionPolicyName", + "SqlAgentConfigurationPropertiesState", + "StorageCapabilityStorageAccountType", + "StorageKeyType", + "SyncAgentState", + "SyncConflictResolutionPolicy", + "SyncDirection", + "SyncGroupLogType", + "SyncGroupState", + "SyncGroupsType", + "SyncMemberDbType", + "SyncMemberState", + "TableTemporalType", + "TransparentDataEncryptionName", + "TransparentDataEncryptionState", + "UnitDefinitionType", + "UnitType", + "UpsertManagedServerOperationStepStatus", + "VirtualNetworkRuleState", + "VulnerabilityAssessmentName", + "VulnerabilityAssessmentPolicyBaselineName", + "VulnerabilityAssessmentScanState", + "VulnerabilityAssessmentScanTriggerType", ] __all__.extend([p for p in _patch_all if p not in __all__]) -_patch_sdk() \ No newline at end of file +_patch_sdk() diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/models/_models_py3.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/models/_models_py3.py index c0a21a0ef0b27..c09b5da475af1 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/models/_models_py3.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/models/_models_py3.py @@ -1,4 +1,5 @@ # coding=utf-8 +# pylint: disable=too-many-lines # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. @@ -9,14 +10,14 @@ import datetime from typing import Dict, List, Optional, TYPE_CHECKING, Union -import msrest.serialization +from .. import _serialization if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports - import __init__ as _models + from .. import models as _models -class AdministratorListResult(msrest.serialization.Model): +class AdministratorListResult(_serialization.Model): """A list of active directory administrators. Variables are only populated by the server, and will be ignored when sending a request. @@ -28,27 +29,23 @@ class AdministratorListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ServerAzureADAdministrator]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ServerAzureADAdministrator]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(AdministratorListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class Resource(msrest.serialization.Model): +class Resource(_serialization.Model): """ARM resource. Variables are only populated by the server, and will be ignored when sending a request. @@ -62,24 +59,20 @@ class Resource(msrest.serialization.Model): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(Resource, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.id = None self.name = None self.type = None @@ -99,27 +92,23 @@ class ProxyResource(Resource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ProxyResource, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) -class Advisor(ProxyResource): +class Advisor(ProxyResource): # pylint: disable=too-many-instance-attributes """Database, Server or Elastic Pool Advisor. Variables are only populated by the server, and will be ignored when sending a request. @@ -136,17 +125,17 @@ class Advisor(ProxyResource): :vartype location: str :ivar advisor_status: Gets the status of availability of this advisor to customers. Possible values are 'GA', 'PublicPreview', 'LimitedPublicPreview' and 'PrivatePreview'. Known values - are: "GA", "PublicPreview", "LimitedPublicPreview", "PrivatePreview". + are: "GA", "PublicPreview", "LimitedPublicPreview", and "PrivatePreview". :vartype advisor_status: str or ~azure.mgmt.sql.models.AdvisorStatus :ivar auto_execute_status: Gets the auto-execute status (whether to let the system execute the recommendations) of this advisor. Possible values are 'Enabled' and 'Disabled'. Known values - are: "Enabled", "Disabled", "Default". + are: "Enabled", "Disabled", and "Default". :vartype auto_execute_status: str or ~azure.mgmt.sql.models.AutoExecuteStatus :ivar auto_execute_status_inherited_from: Gets the resource from which current value of auto-execute status is inherited. Auto-execute status can be set on (and inherited from) different levels in the resource hierarchy. Possible values are 'Subscription', 'Server', 'ElasticPool', 'Database' and 'Default' (when status is not explicitly set on any level). Known - values are: "Default", "Subscription", "Server", "ElasticPool", "Database". + values are: "Default", "Subscription", "Server", "ElasticPool", and "Database". :vartype auto_execute_status_inherited_from: str or ~azure.mgmt.sql.models.AutoExecuteStatusInheritedFrom :ivar recommendations_status: Gets that status of recommendations for this advisor and reason @@ -162,45 +151,40 @@ class Advisor(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'kind': {'readonly': True}, - 'location': {'readonly': True}, - 'advisor_status': {'readonly': True}, - 'auto_execute_status_inherited_from': {'readonly': True}, - 'recommendations_status': {'readonly': True}, - 'last_checked': {'readonly': True}, - 'recommended_actions': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "kind": {"readonly": True}, + "location": {"readonly": True}, + "advisor_status": {"readonly": True}, + "auto_execute_status_inherited_from": {"readonly": True}, + "recommendations_status": {"readonly": True}, + "last_checked": {"readonly": True}, + "recommended_actions": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'kind': {'key': 'kind', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'advisor_status': {'key': 'properties.advisorStatus', 'type': 'str'}, - 'auto_execute_status': {'key': 'properties.autoExecuteStatus', 'type': 'str'}, - 'auto_execute_status_inherited_from': {'key': 'properties.autoExecuteStatusInheritedFrom', 'type': 'str'}, - 'recommendations_status': {'key': 'properties.recommendationsStatus', 'type': 'str'}, - 'last_checked': {'key': 'properties.lastChecked', 'type': 'iso-8601'}, - 'recommended_actions': {'key': 'properties.recommendedActions', 'type': '[RecommendedAction]'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "kind": {"key": "kind", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "advisor_status": {"key": "properties.advisorStatus", "type": "str"}, + "auto_execute_status": {"key": "properties.autoExecuteStatus", "type": "str"}, + "auto_execute_status_inherited_from": {"key": "properties.autoExecuteStatusInheritedFrom", "type": "str"}, + "recommendations_status": {"key": "properties.recommendationsStatus", "type": "str"}, + "last_checked": {"key": "properties.lastChecked", "type": "iso-8601"}, + "recommended_actions": {"key": "properties.recommendedActions", "type": "[RecommendedAction]"}, } - def __init__( - self, - *, - auto_execute_status: Optional[Union[str, "_models.AutoExecuteStatus"]] = None, - **kwargs - ): + def __init__(self, *, auto_execute_status: Optional[Union[str, "_models.AutoExecuteStatus"]] = None, **kwargs): """ :keyword auto_execute_status: Gets the auto-execute status (whether to let the system execute the recommendations) of this advisor. Possible values are 'Enabled' and 'Disabled'. Known - values are: "Enabled", "Disabled", "Default". + values are: "Enabled", "Disabled", and "Default". :paramtype auto_execute_status: str or ~azure.mgmt.sql.models.AutoExecuteStatus """ - super(Advisor, self).__init__(**kwargs) + super().__init__(**kwargs) self.kind = None self.location = None self.advisor_status = None @@ -211,104 +195,98 @@ def __init__( self.recommended_actions = None -class AutomaticTuningOptions(msrest.serialization.Model): +class AutomaticTuningOptions(_serialization.Model): """Automatic tuning properties for individual advisors. Variables are only populated by the server, and will be ignored when sending a request. - :ivar desired_state: Automatic tuning option desired state. Known values are: "Off", "On", + :ivar desired_state: Automatic tuning option desired state. Known values are: "Off", "On", and "Default". :vartype desired_state: str or ~azure.mgmt.sql.models.AutomaticTuningOptionModeDesired - :ivar actual_state: Automatic tuning option actual state. Known values are: "Off", "On". + :ivar actual_state: Automatic tuning option actual state. Known values are: "Off" and "On". :vartype actual_state: str or ~azure.mgmt.sql.models.AutomaticTuningOptionModeActual :ivar reason_code: Reason code if desired and actual state are different. :vartype reason_code: int :ivar reason_desc: Reason description if desired and actual state are different. Known values are: "Default", "Disabled", "AutoConfigured", "InheritedFromServer", "QueryStoreOff", - "QueryStoreReadOnly", "NotSupported". + "QueryStoreReadOnly", and "NotSupported". :vartype reason_desc: str or ~azure.mgmt.sql.models.AutomaticTuningDisabledReason """ _validation = { - 'actual_state': {'readonly': True}, - 'reason_code': {'readonly': True}, - 'reason_desc': {'readonly': True}, + "actual_state": {"readonly": True}, + "reason_code": {"readonly": True}, + "reason_desc": {"readonly": True}, } _attribute_map = { - 'desired_state': {'key': 'desiredState', 'type': 'str'}, - 'actual_state': {'key': 'actualState', 'type': 'str'}, - 'reason_code': {'key': 'reasonCode', 'type': 'int'}, - 'reason_desc': {'key': 'reasonDesc', 'type': 'str'}, + "desired_state": {"key": "desiredState", "type": "str"}, + "actual_state": {"key": "actualState", "type": "str"}, + "reason_code": {"key": "reasonCode", "type": "int"}, + "reason_desc": {"key": "reasonDesc", "type": "str"}, } def __init__( - self, - *, - desired_state: Optional[Union[str, "_models.AutomaticTuningOptionModeDesired"]] = None, - **kwargs + self, *, desired_state: Optional[Union[str, "_models.AutomaticTuningOptionModeDesired"]] = None, **kwargs ): """ :keyword desired_state: Automatic tuning option desired state. Known values are: "Off", "On", - "Default". + and "Default". :paramtype desired_state: str or ~azure.mgmt.sql.models.AutomaticTuningOptionModeDesired """ - super(AutomaticTuningOptions, self).__init__(**kwargs) + super().__init__(**kwargs) self.desired_state = desired_state self.actual_state = None self.reason_code = None self.reason_desc = None -class AutomaticTuningServerOptions(msrest.serialization.Model): +class AutomaticTuningServerOptions(_serialization.Model): """Automatic tuning properties for individual advisors. Variables are only populated by the server, and will be ignored when sending a request. - :ivar desired_state: Automatic tuning option desired state. Known values are: "Off", "On", + :ivar desired_state: Automatic tuning option desired state. Known values are: "Off", "On", and "Default". :vartype desired_state: str or ~azure.mgmt.sql.models.AutomaticTuningOptionModeDesired - :ivar actual_state: Automatic tuning option actual state. Known values are: "Off", "On". + :ivar actual_state: Automatic tuning option actual state. Known values are: "Off" and "On". :vartype actual_state: str or ~azure.mgmt.sql.models.AutomaticTuningOptionModeActual :ivar reason_code: Reason code if desired and actual state are different. :vartype reason_code: int :ivar reason_desc: Reason description if desired and actual state are different. Known values - are: "Default", "Disabled", "AutoConfigured". + are: "Default", "Disabled", and "AutoConfigured". :vartype reason_desc: str or ~azure.mgmt.sql.models.AutomaticTuningServerReason """ _validation = { - 'actual_state': {'readonly': True}, - 'reason_code': {'readonly': True}, - 'reason_desc': {'readonly': True}, + "actual_state": {"readonly": True}, + "reason_code": {"readonly": True}, + "reason_desc": {"readonly": True}, } _attribute_map = { - 'desired_state': {'key': 'desiredState', 'type': 'str'}, - 'actual_state': {'key': 'actualState', 'type': 'str'}, - 'reason_code': {'key': 'reasonCode', 'type': 'int'}, - 'reason_desc': {'key': 'reasonDesc', 'type': 'str'}, + "desired_state": {"key": "desiredState", "type": "str"}, + "actual_state": {"key": "actualState", "type": "str"}, + "reason_code": {"key": "reasonCode", "type": "int"}, + "reason_desc": {"key": "reasonDesc", "type": "str"}, } def __init__( - self, - *, - desired_state: Optional[Union[str, "_models.AutomaticTuningOptionModeDesired"]] = None, - **kwargs + self, *, desired_state: Optional[Union[str, "_models.AutomaticTuningOptionModeDesired"]] = None, **kwargs ): """ :keyword desired_state: Automatic tuning option desired state. Known values are: "Off", "On", - "Default". + and "Default". :paramtype desired_state: str or ~azure.mgmt.sql.models.AutomaticTuningOptionModeDesired """ - super(AutomaticTuningServerOptions, self).__init__(**kwargs) + super().__init__(**kwargs) self.desired_state = desired_state self.actual_state = None self.reason_code = None self.reason_desc = None -class AutoPauseDelayTimeRange(msrest.serialization.Model): +class AutoPauseDelayTimeRange(_serialization.Model): """Supported auto pause delay time range. Variables are only populated by the server, and will be ignored when sending a request. @@ -322,37 +300,33 @@ class AutoPauseDelayTimeRange(msrest.serialization.Model): :vartype step_size: int :ivar default: Default value is no value is provided. :vartype default: int - :ivar unit: Unit of time that delay is expressed in. Known values are: "Minutes". + :ivar unit: Unit of time that delay is expressed in. "Minutes" :vartype unit: str or ~azure.mgmt.sql.models.PauseDelayTimeUnit :ivar do_not_pause_value: Value that is used to not pause (infinite delay before pause). :vartype do_not_pause_value: int """ _validation = { - 'min_value': {'readonly': True}, - 'max_value': {'readonly': True}, - 'step_size': {'readonly': True}, - 'default': {'readonly': True}, - 'unit': {'readonly': True}, - 'do_not_pause_value': {'readonly': True}, + "min_value": {"readonly": True}, + "max_value": {"readonly": True}, + "step_size": {"readonly": True}, + "default": {"readonly": True}, + "unit": {"readonly": True}, + "do_not_pause_value": {"readonly": True}, } _attribute_map = { - 'min_value': {'key': 'minValue', 'type': 'int'}, - 'max_value': {'key': 'maxValue', 'type': 'int'}, - 'step_size': {'key': 'stepSize', 'type': 'int'}, - 'default': {'key': 'default', 'type': 'int'}, - 'unit': {'key': 'unit', 'type': 'str'}, - 'do_not_pause_value': {'key': 'doNotPauseValue', 'type': 'int'}, + "min_value": {"key": "minValue", "type": "int"}, + "max_value": {"key": "maxValue", "type": "int"}, + "step_size": {"key": "stepSize", "type": "int"}, + "default": {"key": "default", "type": "int"}, + "unit": {"key": "unit", "type": "str"}, + "do_not_pause_value": {"key": "doNotPauseValue", "type": "int"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(AutoPauseDelayTimeRange, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.min_value = None self.max_value = None self.step_size = None @@ -361,7 +335,7 @@ def __init__( self.do_not_pause_value = None -class AzureADOnlyAuthListResult(msrest.serialization.Model): +class AzureADOnlyAuthListResult(_serialization.Model): """A list of active directory only authentications. Variables are only populated by the server, and will be ignored when sending a request. @@ -373,22 +347,18 @@ class AzureADOnlyAuthListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ServerAzureADOnlyAuthentication]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ServerAzureADOnlyAuthentication]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(AzureADOnlyAuthListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -409,22 +379,22 @@ class BackupShortTermRetentionPolicy(ProxyResource): :vartype retention_days: int :ivar diff_backup_interval_in_hours: The differential backup interval in hours. This is how many interval hours between each differential backup will be supported. This is only applicable - to live databases but not dropped databases. Known values are: 12, 24. + to live databases but not dropped databases. Known values are: 12 and 24. :vartype diff_backup_interval_in_hours: int or ~azure.mgmt.sql.models.DiffBackupIntervalInHours """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'retention_days': {'key': 'properties.retentionDays', 'type': 'int'}, - 'diff_backup_interval_in_hours': {'key': 'properties.diffBackupIntervalInHours', 'type': 'int'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "retention_days": {"key": "properties.retentionDays", "type": "int"}, + "diff_backup_interval_in_hours": {"key": "properties.diffBackupIntervalInHours", "type": "int"}, } def __init__( @@ -440,16 +410,16 @@ def __init__( :paramtype retention_days: int :keyword diff_backup_interval_in_hours: The differential backup interval in hours. This is how many interval hours between each differential backup will be supported. This is only applicable - to live databases but not dropped databases. Known values are: 12, 24. + to live databases but not dropped databases. Known values are: 12 and 24. :paramtype diff_backup_interval_in_hours: int or ~azure.mgmt.sql.models.DiffBackupIntervalInHours """ - super(BackupShortTermRetentionPolicy, self).__init__(**kwargs) + super().__init__(**kwargs) self.retention_days = retention_days self.diff_backup_interval_in_hours = diff_backup_interval_in_hours -class BackupShortTermRetentionPolicyListResult(msrest.serialization.Model): +class BackupShortTermRetentionPolicyListResult(_serialization.Model): """A list of short term retention policies. Variables are only populated by the server, and will be ignored when sending a request. @@ -461,27 +431,23 @@ class BackupShortTermRetentionPolicyListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[BackupShortTermRetentionPolicy]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[BackupShortTermRetentionPolicy]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(BackupShortTermRetentionPolicyListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class CheckNameAvailabilityRequest(msrest.serialization.Model): +class CheckNameAvailabilityRequest(_serialization.Model): """A request to check whether the specified name for a resource is available. Variables are only populated by the server, and will be ignored when sending a request. @@ -490,37 +456,32 @@ class CheckNameAvailabilityRequest(msrest.serialization.Model): :ivar name: Required. :vartype name: str - :ivar type: Has constant value: "Microsoft.Sql/servers". + :ivar type: Required. Default value is "Microsoft.Sql/servers". :vartype type: str """ _validation = { - 'name': {'required': True}, - 'type': {'required': True, 'constant': True}, + "name": {"required": True}, + "type": {"required": True, "constant": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, } type = "Microsoft.Sql/servers" - def __init__( - self, - *, - name: str, - **kwargs - ): + def __init__(self, *, name: str, **kwargs): """ :keyword name: Required. :paramtype name: str """ - super(CheckNameAvailabilityRequest, self).__init__(**kwargs) + super().__init__(**kwargs) self.name = name -class CheckNameAvailabilityResponse(msrest.serialization.Model): +class CheckNameAvailabilityResponse(_serialization.Model): """The result of a name availability check. Variables are only populated by the server, and will be ignored when sending a request. @@ -530,7 +491,7 @@ class CheckNameAvailabilityResponse(msrest.serialization.Model): :ivar available: True if the name is available, otherwise false. :vartype available: bool :ivar reason: The reason code explaining why the name is unavailable. Will be undefined if the - name is available. Known values are: "Invalid", "AlreadyExists". + name is available. Known values are: "Invalid" and "AlreadyExists". :vartype reason: str or ~azure.mgmt.sql.models.CheckNameAvailabilityReason :ivar message: A message explaining why the name is unavailable. Will be undefined if the name is available. @@ -538,64 +499,55 @@ class CheckNameAvailabilityResponse(msrest.serialization.Model): """ _validation = { - 'name': {'readonly': True}, - 'available': {'readonly': True}, - 'reason': {'readonly': True}, - 'message': {'readonly': True}, + "name": {"readonly": True}, + "available": {"readonly": True}, + "reason": {"readonly": True}, + "message": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'available': {'key': 'available', 'type': 'bool'}, - 'reason': {'key': 'reason', 'type': 'str'}, - 'message': {'key': 'message', 'type': 'str'}, + "name": {"key": "name", "type": "str"}, + "available": {"key": "available", "type": "bool"}, + "reason": {"key": "reason", "type": "str"}, + "message": {"key": "message", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(CheckNameAvailabilityResponse, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.name = None self.available = None self.reason = None self.message = None -class CompleteDatabaseRestoreDefinition(msrest.serialization.Model): +class CompleteDatabaseRestoreDefinition(_serialization.Model): """Contains the information necessary to perform a complete database restore operation. All required parameters must be populated in order to send to Azure. - :ivar last_backup_name: Required. The last backup name to apply. + :ivar last_backup_name: The last backup name to apply. Required. :vartype last_backup_name: str """ _validation = { - 'last_backup_name': {'required': True}, + "last_backup_name": {"required": True}, } _attribute_map = { - 'last_backup_name': {'key': 'lastBackupName', 'type': 'str'}, + "last_backup_name": {"key": "lastBackupName", "type": "str"}, } - def __init__( - self, - *, - last_backup_name: str, - **kwargs - ): + def __init__(self, *, last_backup_name: str, **kwargs): """ - :keyword last_backup_name: Required. The last backup name to apply. + :keyword last_backup_name: The last backup name to apply. Required. :paramtype last_backup_name: str """ - super(CompleteDatabaseRestoreDefinition, self).__init__(**kwargs) + super().__init__(**kwargs) self.last_backup_name = last_backup_name -class CopyLongTermRetentionBackupParameters(msrest.serialization.Model): +class CopyLongTermRetentionBackupParameters(_serialization.Model): """Contains the information necessary to perform long term retention backup copy operation. :ivar target_subscription_id: The subscription that owns the target server. @@ -610,18 +562,21 @@ class CopyLongTermRetentionBackupParameters(msrest.serialization.Model): :ivar target_database_name: The name of the database owns the copied backup. :vartype target_database_name: str :ivar target_backup_storage_redundancy: The storage redundancy type of the copied backup. Known - values are: "Geo", "Local", "Zone", "GeoZone". + values are: "Geo", "Local", "Zone", and "GeoZone". :vartype target_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy """ _attribute_map = { - 'target_subscription_id': {'key': 'properties.targetSubscriptionId', 'type': 'str'}, - 'target_resource_group': {'key': 'properties.targetResourceGroup', 'type': 'str'}, - 'target_server_resource_id': {'key': 'properties.targetServerResourceId', 'type': 'str'}, - 'target_server_fully_qualified_domain_name': {'key': 'properties.targetServerFullyQualifiedDomainName', 'type': 'str'}, - 'target_database_name': {'key': 'properties.targetDatabaseName', 'type': 'str'}, - 'target_backup_storage_redundancy': {'key': 'properties.targetBackupStorageRedundancy', 'type': 'str'}, + "target_subscription_id": {"key": "properties.targetSubscriptionId", "type": "str"}, + "target_resource_group": {"key": "properties.targetResourceGroup", "type": "str"}, + "target_server_resource_id": {"key": "properties.targetServerResourceId", "type": "str"}, + "target_server_fully_qualified_domain_name": { + "key": "properties.targetServerFullyQualifiedDomainName", + "type": "str", + }, + "target_database_name": {"key": "properties.targetDatabaseName", "type": "str"}, + "target_backup_storage_redundancy": {"key": "properties.targetBackupStorageRedundancy", "type": "str"}, } def __init__( @@ -649,11 +604,11 @@ def __init__( :keyword target_database_name: The name of the database owns the copied backup. :paramtype target_database_name: str :keyword target_backup_storage_redundancy: The storage redundancy type of the copied backup. - Known values are: "Geo", "Local", "Zone", "GeoZone". + Known values are: "Geo", "Local", "Zone", and "GeoZone". :paramtype target_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy """ - super(CopyLongTermRetentionBackupParameters, self).__init__(**kwargs) + super().__init__(**kwargs) self.target_subscription_id = target_subscription_id self.target_resource_group = target_resource_group self.target_server_resource_id = target_server_resource_id @@ -662,34 +617,29 @@ def __init__( self.target_backup_storage_redundancy = target_backup_storage_redundancy -class CreateDatabaseRestorePointDefinition(msrest.serialization.Model): +class CreateDatabaseRestorePointDefinition(_serialization.Model): """Contains the information necessary to perform a create database restore point operation. All required parameters must be populated in order to send to Azure. - :ivar restore_point_label: Required. The restore point label to apply. + :ivar restore_point_label: The restore point label to apply. Required. :vartype restore_point_label: str """ _validation = { - 'restore_point_label': {'required': True}, + "restore_point_label": {"required": True}, } _attribute_map = { - 'restore_point_label': {'key': 'restorePointLabel', 'type': 'str'}, + "restore_point_label": {"key": "restorePointLabel", "type": "str"}, } - def __init__( - self, - *, - restore_point_label: str, - **kwargs - ): + def __init__(self, *, restore_point_label: str, **kwargs): """ - :keyword restore_point_label: Required. The restore point label to apply. + :keyword restore_point_label: The restore point label to apply. Required. :paramtype restore_point_label: str """ - super(CreateDatabaseRestorePointDefinition, self).__init__(**kwargs) + super().__init__(**kwargs) self.restore_point_label = restore_point_label @@ -706,46 +656,40 @@ class TrackedResource(Resource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar location: Required. Resource location. + :ivar location: Resource location. Required. :vartype location: str - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'location': {'required': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "location": {"required": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'tags': {'key': 'tags', 'type': '{str}'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "tags": {"key": "tags", "type": "{str}"}, } - def __init__( - self, - *, - location: str, - tags: Optional[Dict[str, str]] = None, - **kwargs - ): + def __init__(self, *, location: str, tags: Optional[Dict[str, str]] = None, **kwargs): """ - :keyword location: Required. Resource location. + :keyword location: Resource location. Required. :paramtype location: str - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] """ - super(TrackedResource, self).__init__(**kwargs) + super().__init__(**kwargs) self.location = location self.tags = tags -class Database(TrackedResource): +class Database(TrackedResource): # pylint: disable=too-many-instance-attributes """A database resource. Variables are only populated by the server, and will be ignored when sending a request. @@ -758,24 +702,24 @@ class Database(TrackedResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar location: Required. Resource location. + :ivar location: Resource location. Required. :vartype location: str - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar sku: The database SKU. - + The list of SKUs may vary by region and support offer. To determine the SKUs (including the SKU name, tier/edition, family, and capacity) that are available to your subscription in an Azure region, use the ``Capabilities_ListByLocation`` REST API or one of the following commands: - + .. code-block:: azurecli - + az sql db list-editions -l -o table ` - + .. code-block:: powershell - + Get-AzSqlServerServiceObjective -Location `. :vartype sku: ~azure.mgmt.sql.models.Sku @@ -786,43 +730,43 @@ class Database(TrackedResource): :ivar identity: The Azure Active Directory identity of the database. :vartype identity: ~azure.mgmt.sql.models.DatabaseIdentity :ivar create_mode: Specifies the mode of database creation. - + Default: regular database creation. - + Copy: creates a database as a copy of an existing database. sourceDatabaseId must be specified as the resource ID of the source database. - + Secondary: creates a database as a secondary replica of an existing database. sourceDatabaseId must be specified as the resource ID of the existing primary database. - + PointInTimeRestore: Creates a database by restoring a point in time backup of an existing database. sourceDatabaseId must be specified as the resource ID of the existing database, and restorePointInTime must be specified. - + Recovery: Creates a database by restoring a geo-replicated backup. sourceDatabaseId must be specified as the recoverable database resource ID to restore. - + Restore: Creates a database by restoring a backup of a deleted database. sourceDatabaseId must be specified. If sourceDatabaseId is the database's original resource ID, then sourceDatabaseDeletionDate must be specified. Otherwise sourceDatabaseId must be the restorable dropped database resource ID and sourceDatabaseDeletionDate is ignored. restorePointInTime may also be specified to restore from an earlier point in time. - + RestoreLongTermRetentionBackup: Creates a database by restoring from a long term retention vault. recoveryServicesRecoveryPointResourceId must be specified as the recovery point resource ID. - + Copy, Secondary, and RestoreLongTermRetentionBackup are not supported for DataWarehouse edition. Known values are: "Default", "Copy", "Secondary", "PointInTimeRestore", "Restore", "Recovery", "RestoreExternalBackup", "RestoreExternalBackupSecondary", - "RestoreLongTermRetentionBackup", "OnlineSecondary". + "RestoreLongTermRetentionBackup", and "OnlineSecondary". :vartype create_mode: str or ~azure.mgmt.sql.models.CreateMode :ivar collation: The collation of the database. :vartype collation: str :ivar max_size_bytes: The max size of the database expressed in bytes. - :vartype max_size_bytes: long + :vartype max_size_bytes: int :ivar sample_name: The name of the sample schema to apply when creating this database. Known - values are: "AdventureWorksLT", "WideWorldImportersStd", "WideWorldImportersFull". + values are: "AdventureWorksLT", "WideWorldImportersStd", and "WideWorldImportersFull". :vartype sample_name: str or ~azure.mgmt.sql.models.SampleName :ivar elastic_pool_id: The resource identifier of the elastic pool containing this database. :vartype elastic_pool_id: str @@ -833,7 +777,7 @@ class Database(TrackedResource): "RecoveryPending", "Recovering", "Suspect", "Offline", "Standby", "Shutdown", "EmergencyMode", "AutoClosed", "Copying", "Creating", "Inaccessible", "OfflineSecondary", "Pausing", "Paused", "Resuming", "Scaling", "OfflineChangingDwPerformanceTiers", "OnlineChangingDwPerformanceTiers", - "Disabled", "Stopping", "Stopped", "Starting". + "Disabled", "Stopping", "Stopped", and "Starting". :vartype status: str or ~azure.mgmt.sql.models.DatabaseStatus :ivar database_id: The ID of the database. :vartype database_id: str @@ -866,31 +810,31 @@ class Database(TrackedResource): database associated with create operation of this database. :vartype restorable_dropped_database_id: str :ivar catalog_collation: Collation of the metadata catalog. Known values are: - "DATABASE_DEFAULT", "SQL_Latin1_General_CP1_CI_AS". + "DATABASE_DEFAULT" and "SQL_Latin1_General_CP1_CI_AS". :vartype catalog_collation: str or ~azure.mgmt.sql.models.CatalogCollationType :ivar zone_redundant: Whether or not this database is zone redundant, which means the replicas of this database will be spread across multiple availability zones. :vartype zone_redundant: bool :ivar license_type: The license type to apply for this database. ``LicenseIncluded`` if you need a license, or ``BasePrice`` if you have a license and are eligible for the Azure Hybrid - Benefit. Known values are: "LicenseIncluded", "BasePrice". + Benefit. Known values are: "LicenseIncluded" and "BasePrice". :vartype license_type: str or ~azure.mgmt.sql.models.DatabaseLicenseType :ivar max_log_size_bytes: The max log size for this database. - :vartype max_log_size_bytes: long + :vartype max_log_size_bytes: int :ivar earliest_restore_date: This records the earliest start date and time that restore is available for this database (ISO8601 format). :vartype earliest_restore_date: ~datetime.datetime :ivar read_scale: The state of read-only routing. If enabled, connections that have application intent set to readonly in their connection string may be routed to a readonly secondary replica in the same region. Not applicable to a Hyperscale database within an elastic pool. Known - values are: "Enabled", "Disabled". + values are: "Enabled" and "Disabled". :vartype read_scale: str or ~azure.mgmt.sql.models.DatabaseReadScale :ivar high_availability_replica_count: The number of secondary replicas associated with the database that are used to provide high availability. Not applicable to a Hyperscale database within an elastic pool. :vartype high_availability_replica_count: int :ivar secondary_type: The secondary type of the database if it is a secondary. Valid values - are Geo and Named. Known values are: "Geo", "Named". + are Geo, Named and Standby. Known values are: "Geo", "Named", and "Standby". :vartype secondary_type: str or ~azure.mgmt.sql.models.SecondaryType :ivar current_sku: The name and tier of the SKU. :vartype current_sku: ~azure.mgmt.sql.models.Sku @@ -898,11 +842,11 @@ class Database(TrackedResource): of -1 means that automatic pause is disabled. :vartype auto_pause_delay: int :ivar current_backup_storage_redundancy: The storage account type used to store backups for - this database. Known values are: "Geo", "Local", "Zone", "GeoZone". + this database. Known values are: "Geo", "Local", "Zone", and "GeoZone". :vartype current_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy :ivar requested_backup_storage_redundancy: The storage account type to be used to store backups - for this database. Known values are: "Geo", "Local", "Zone", "GeoZone". + for this database. Known values are: "Geo", "Local", "Zone", and "GeoZone". :vartype requested_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy :ivar min_capacity: Minimal capacity that database will always have allocated, if not paused. @@ -926,23 +870,23 @@ class Database(TrackedResource): :vartype federated_client_id: str :ivar source_resource_id: The resource identifier of the source associated with the create operation of this database. - + + This property is only supported for DataWarehouse edition and allows to restore across + subscriptions. + When sourceResourceId is specified, sourceDatabaseId, recoverableDatabaseId, restorableDroppedDatabaseId and sourceDatabaseDeletionDate must not be specified and CreateMode must be PointInTimeRestore, Restore or Recover. - - When createMode is PointInTimeRestore, sourceResourceId must be the resource ID of an existing - database or existing sql pool, and restorePointInTime must be specified. - + + When createMode is PointInTimeRestore, sourceResourceId must be the resource ID of the + existing database or existing sql pool, and restorePointInTime must be specified. + When createMode is Restore, sourceResourceId must be the resource ID of restorable dropped database or restorable dropped sql pool. - + When createMode is Recover, sourceResourceId must be the resource ID of recoverable database or recoverable sql pool. - - This property allows to restore across subscriptions which is only supported for DataWarehouse - edition. - + When source subscription belongs to a different tenant than target subscription, “x-ms-authorization-auxiliary” header must contain authentication token for the source tenant. For more details about “x-ms-authorization-auxiliary” header see @@ -951,80 +895,83 @@ class Database(TrackedResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'location': {'required': True}, - 'kind': {'readonly': True}, - 'managed_by': {'readonly': True}, - 'status': {'readonly': True}, - 'database_id': {'readonly': True}, - 'creation_date': {'readonly': True}, - 'current_service_objective_name': {'readonly': True}, - 'requested_service_objective_name': {'readonly': True}, - 'default_secondary_location': {'readonly': True}, - 'failover_group_id': {'readonly': True}, - 'max_log_size_bytes': {'readonly': True}, - 'earliest_restore_date': {'readonly': True}, - 'current_sku': {'readonly': True}, - 'current_backup_storage_redundancy': {'readonly': True}, - 'paused_date': {'readonly': True}, - 'resumed_date': {'readonly': True}, - 'is_infra_encryption_enabled': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'tags': {'key': 'tags', 'type': '{str}'}, - 'sku': {'key': 'sku', 'type': 'Sku'}, - 'kind': {'key': 'kind', 'type': 'str'}, - 'managed_by': {'key': 'managedBy', 'type': 'str'}, - 'identity': {'key': 'identity', 'type': 'DatabaseIdentity'}, - 'create_mode': {'key': 'properties.createMode', 'type': 'str'}, - 'collation': {'key': 'properties.collation', 'type': 'str'}, - 'max_size_bytes': {'key': 'properties.maxSizeBytes', 'type': 'long'}, - 'sample_name': {'key': 'properties.sampleName', 'type': 'str'}, - 'elastic_pool_id': {'key': 'properties.elasticPoolId', 'type': 'str'}, - 'source_database_id': {'key': 'properties.sourceDatabaseId', 'type': 'str'}, - 'status': {'key': 'properties.status', 'type': 'str'}, - 'database_id': {'key': 'properties.databaseId', 'type': 'str'}, - 'creation_date': {'key': 'properties.creationDate', 'type': 'iso-8601'}, - 'current_service_objective_name': {'key': 'properties.currentServiceObjectiveName', 'type': 'str'}, - 'requested_service_objective_name': {'key': 'properties.requestedServiceObjectiveName', 'type': 'str'}, - 'default_secondary_location': {'key': 'properties.defaultSecondaryLocation', 'type': 'str'}, - 'failover_group_id': {'key': 'properties.failoverGroupId', 'type': 'str'}, - 'restore_point_in_time': {'key': 'properties.restorePointInTime', 'type': 'iso-8601'}, - 'source_database_deletion_date': {'key': 'properties.sourceDatabaseDeletionDate', 'type': 'iso-8601'}, - 'recovery_services_recovery_point_id': {'key': 'properties.recoveryServicesRecoveryPointId', 'type': 'str'}, - 'long_term_retention_backup_resource_id': {'key': 'properties.longTermRetentionBackupResourceId', 'type': 'str'}, - 'recoverable_database_id': {'key': 'properties.recoverableDatabaseId', 'type': 'str'}, - 'restorable_dropped_database_id': {'key': 'properties.restorableDroppedDatabaseId', 'type': 'str'}, - 'catalog_collation': {'key': 'properties.catalogCollation', 'type': 'str'}, - 'zone_redundant': {'key': 'properties.zoneRedundant', 'type': 'bool'}, - 'license_type': {'key': 'properties.licenseType', 'type': 'str'}, - 'max_log_size_bytes': {'key': 'properties.maxLogSizeBytes', 'type': 'long'}, - 'earliest_restore_date': {'key': 'properties.earliestRestoreDate', 'type': 'iso-8601'}, - 'read_scale': {'key': 'properties.readScale', 'type': 'str'}, - 'high_availability_replica_count': {'key': 'properties.highAvailabilityReplicaCount', 'type': 'int'}, - 'secondary_type': {'key': 'properties.secondaryType', 'type': 'str'}, - 'current_sku': {'key': 'properties.currentSku', 'type': 'Sku'}, - 'auto_pause_delay': {'key': 'properties.autoPauseDelay', 'type': 'int'}, - 'current_backup_storage_redundancy': {'key': 'properties.currentBackupStorageRedundancy', 'type': 'str'}, - 'requested_backup_storage_redundancy': {'key': 'properties.requestedBackupStorageRedundancy', 'type': 'str'}, - 'min_capacity': {'key': 'properties.minCapacity', 'type': 'float'}, - 'paused_date': {'key': 'properties.pausedDate', 'type': 'iso-8601'}, - 'resumed_date': {'key': 'properties.resumedDate', 'type': 'iso-8601'}, - 'maintenance_configuration_id': {'key': 'properties.maintenanceConfigurationId', 'type': 'str'}, - 'is_ledger_on': {'key': 'properties.isLedgerOn', 'type': 'bool'}, - 'is_infra_encryption_enabled': {'key': 'properties.isInfraEncryptionEnabled', 'type': 'bool'}, - 'federated_client_id': {'key': 'properties.federatedClientId', 'type': 'str'}, - 'source_resource_id': {'key': 'properties.sourceResourceId', 'type': 'str'}, - } - - def __init__( + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "location": {"required": True}, + "kind": {"readonly": True}, + "managed_by": {"readonly": True}, + "status": {"readonly": True}, + "database_id": {"readonly": True}, + "creation_date": {"readonly": True}, + "current_service_objective_name": {"readonly": True}, + "requested_service_objective_name": {"readonly": True}, + "default_secondary_location": {"readonly": True}, + "failover_group_id": {"readonly": True}, + "max_log_size_bytes": {"readonly": True}, + "earliest_restore_date": {"readonly": True}, + "current_sku": {"readonly": True}, + "current_backup_storage_redundancy": {"readonly": True}, + "paused_date": {"readonly": True}, + "resumed_date": {"readonly": True}, + "is_infra_encryption_enabled": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "tags": {"key": "tags", "type": "{str}"}, + "sku": {"key": "sku", "type": "Sku"}, + "kind": {"key": "kind", "type": "str"}, + "managed_by": {"key": "managedBy", "type": "str"}, + "identity": {"key": "identity", "type": "DatabaseIdentity"}, + "create_mode": {"key": "properties.createMode", "type": "str"}, + "collation": {"key": "properties.collation", "type": "str"}, + "max_size_bytes": {"key": "properties.maxSizeBytes", "type": "int"}, + "sample_name": {"key": "properties.sampleName", "type": "str"}, + "elastic_pool_id": {"key": "properties.elasticPoolId", "type": "str"}, + "source_database_id": {"key": "properties.sourceDatabaseId", "type": "str"}, + "status": {"key": "properties.status", "type": "str"}, + "database_id": {"key": "properties.databaseId", "type": "str"}, + "creation_date": {"key": "properties.creationDate", "type": "iso-8601"}, + "current_service_objective_name": {"key": "properties.currentServiceObjectiveName", "type": "str"}, + "requested_service_objective_name": {"key": "properties.requestedServiceObjectiveName", "type": "str"}, + "default_secondary_location": {"key": "properties.defaultSecondaryLocation", "type": "str"}, + "failover_group_id": {"key": "properties.failoverGroupId", "type": "str"}, + "restore_point_in_time": {"key": "properties.restorePointInTime", "type": "iso-8601"}, + "source_database_deletion_date": {"key": "properties.sourceDatabaseDeletionDate", "type": "iso-8601"}, + "recovery_services_recovery_point_id": {"key": "properties.recoveryServicesRecoveryPointId", "type": "str"}, + "long_term_retention_backup_resource_id": { + "key": "properties.longTermRetentionBackupResourceId", + "type": "str", + }, + "recoverable_database_id": {"key": "properties.recoverableDatabaseId", "type": "str"}, + "restorable_dropped_database_id": {"key": "properties.restorableDroppedDatabaseId", "type": "str"}, + "catalog_collation": {"key": "properties.catalogCollation", "type": "str"}, + "zone_redundant": {"key": "properties.zoneRedundant", "type": "bool"}, + "license_type": {"key": "properties.licenseType", "type": "str"}, + "max_log_size_bytes": {"key": "properties.maxLogSizeBytes", "type": "int"}, + "earliest_restore_date": {"key": "properties.earliestRestoreDate", "type": "iso-8601"}, + "read_scale": {"key": "properties.readScale", "type": "str"}, + "high_availability_replica_count": {"key": "properties.highAvailabilityReplicaCount", "type": "int"}, + "secondary_type": {"key": "properties.secondaryType", "type": "str"}, + "current_sku": {"key": "properties.currentSku", "type": "Sku"}, + "auto_pause_delay": {"key": "properties.autoPauseDelay", "type": "int"}, + "current_backup_storage_redundancy": {"key": "properties.currentBackupStorageRedundancy", "type": "str"}, + "requested_backup_storage_redundancy": {"key": "properties.requestedBackupStorageRedundancy", "type": "str"}, + "min_capacity": {"key": "properties.minCapacity", "type": "float"}, + "paused_date": {"key": "properties.pausedDate", "type": "iso-8601"}, + "resumed_date": {"key": "properties.resumedDate", "type": "iso-8601"}, + "maintenance_configuration_id": {"key": "properties.maintenanceConfigurationId", "type": "str"}, + "is_ledger_on": {"key": "properties.isLedgerOn", "type": "bool"}, + "is_infra_encryption_enabled": {"key": "properties.isInfraEncryptionEnabled", "type": "bool"}, + "federated_client_id": {"key": "properties.federatedClientId", "type": "str"}, + "source_resource_id": {"key": "properties.sourceResourceId", "type": "str"}, + } + + def __init__( # pylint: disable=too-many-locals self, *, location: str, @@ -1059,67 +1006,67 @@ def __init__( **kwargs ): """ - :keyword location: Required. Resource location. + :keyword location: Resource location. Required. :paramtype location: str - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] :keyword sku: The database SKU. - + The list of SKUs may vary by region and support offer. To determine the SKUs (including the SKU name, tier/edition, family, and capacity) that are available to your subscription in an Azure region, use the ``Capabilities_ListByLocation`` REST API or one of the following commands: - + .. code-block:: azurecli - + az sql db list-editions -l -o table ` - + .. code-block:: powershell - + Get-AzSqlServerServiceObjective -Location `. :paramtype sku: ~azure.mgmt.sql.models.Sku :keyword identity: The Azure Active Directory identity of the database. :paramtype identity: ~azure.mgmt.sql.models.DatabaseIdentity :keyword create_mode: Specifies the mode of database creation. - + Default: regular database creation. - + Copy: creates a database as a copy of an existing database. sourceDatabaseId must be specified as the resource ID of the source database. - + Secondary: creates a database as a secondary replica of an existing database. sourceDatabaseId must be specified as the resource ID of the existing primary database. - + PointInTimeRestore: Creates a database by restoring a point in time backup of an existing database. sourceDatabaseId must be specified as the resource ID of the existing database, and restorePointInTime must be specified. - + Recovery: Creates a database by restoring a geo-replicated backup. sourceDatabaseId must be specified as the recoverable database resource ID to restore. - + Restore: Creates a database by restoring a backup of a deleted database. sourceDatabaseId must be specified. If sourceDatabaseId is the database's original resource ID, then sourceDatabaseDeletionDate must be specified. Otherwise sourceDatabaseId must be the restorable dropped database resource ID and sourceDatabaseDeletionDate is ignored. restorePointInTime may also be specified to restore from an earlier point in time. - + RestoreLongTermRetentionBackup: Creates a database by restoring from a long term retention vault. recoveryServicesRecoveryPointResourceId must be specified as the recovery point resource ID. - + Copy, Secondary, and RestoreLongTermRetentionBackup are not supported for DataWarehouse edition. Known values are: "Default", "Copy", "Secondary", "PointInTimeRestore", "Restore", "Recovery", "RestoreExternalBackup", "RestoreExternalBackupSecondary", - "RestoreLongTermRetentionBackup", "OnlineSecondary". + "RestoreLongTermRetentionBackup", and "OnlineSecondary". :paramtype create_mode: str or ~azure.mgmt.sql.models.CreateMode :keyword collation: The collation of the database. :paramtype collation: str :keyword max_size_bytes: The max size of the database expressed in bytes. - :paramtype max_size_bytes: long + :paramtype max_size_bytes: int :keyword sample_name: The name of the sample schema to apply when creating this database. Known - values are: "AdventureWorksLT", "WideWorldImportersStd", "WideWorldImportersFull". + values are: "AdventureWorksLT", "WideWorldImportersStd", and "WideWorldImportersFull". :paramtype sample_name: str or ~azure.mgmt.sql.models.SampleName :keyword elastic_pool_id: The resource identifier of the elastic pool containing this database. :paramtype elastic_pool_id: str @@ -1144,32 +1091,32 @@ def __init__( database associated with create operation of this database. :paramtype restorable_dropped_database_id: str :keyword catalog_collation: Collation of the metadata catalog. Known values are: - "DATABASE_DEFAULT", "SQL_Latin1_General_CP1_CI_AS". + "DATABASE_DEFAULT" and "SQL_Latin1_General_CP1_CI_AS". :paramtype catalog_collation: str or ~azure.mgmt.sql.models.CatalogCollationType :keyword zone_redundant: Whether or not this database is zone redundant, which means the replicas of this database will be spread across multiple availability zones. :paramtype zone_redundant: bool :keyword license_type: The license type to apply for this database. ``LicenseIncluded`` if you need a license, or ``BasePrice`` if you have a license and are eligible for the Azure Hybrid - Benefit. Known values are: "LicenseIncluded", "BasePrice". + Benefit. Known values are: "LicenseIncluded" and "BasePrice". :paramtype license_type: str or ~azure.mgmt.sql.models.DatabaseLicenseType :keyword read_scale: The state of read-only routing. If enabled, connections that have application intent set to readonly in their connection string may be routed to a readonly secondary replica in the same region. Not applicable to a Hyperscale database within an elastic - pool. Known values are: "Enabled", "Disabled". + pool. Known values are: "Enabled" and "Disabled". :paramtype read_scale: str or ~azure.mgmt.sql.models.DatabaseReadScale :keyword high_availability_replica_count: The number of secondary replicas associated with the database that are used to provide high availability. Not applicable to a Hyperscale database within an elastic pool. :paramtype high_availability_replica_count: int :keyword secondary_type: The secondary type of the database if it is a secondary. Valid values - are Geo and Named. Known values are: "Geo", "Named". + are Geo, Named and Standby. Known values are: "Geo", "Named", and "Standby". :paramtype secondary_type: str or ~azure.mgmt.sql.models.SecondaryType :keyword auto_pause_delay: Time in minutes after which database is automatically paused. A value of -1 means that automatic pause is disabled. :paramtype auto_pause_delay: int :keyword requested_backup_storage_redundancy: The storage account type to be used to store - backups for this database. Known values are: "Geo", "Local", "Zone", "GeoZone". + backups for this database. Known values are: "Geo", "Local", "Zone", and "GeoZone". :paramtype requested_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy :keyword min_capacity: Minimal capacity that database will always have allocated, if not @@ -1186,30 +1133,30 @@ def __init__( :paramtype federated_client_id: str :keyword source_resource_id: The resource identifier of the source associated with the create operation of this database. - + + This property is only supported for DataWarehouse edition and allows to restore across + subscriptions. + When sourceResourceId is specified, sourceDatabaseId, recoverableDatabaseId, restorableDroppedDatabaseId and sourceDatabaseDeletionDate must not be specified and CreateMode must be PointInTimeRestore, Restore or Recover. - - When createMode is PointInTimeRestore, sourceResourceId must be the resource ID of an existing - database or existing sql pool, and restorePointInTime must be specified. - + + When createMode is PointInTimeRestore, sourceResourceId must be the resource ID of the + existing database or existing sql pool, and restorePointInTime must be specified. + When createMode is Restore, sourceResourceId must be the resource ID of restorable dropped database or restorable dropped sql pool. - + When createMode is Recover, sourceResourceId must be the resource ID of recoverable database or recoverable sql pool. - - This property allows to restore across subscriptions which is only supported for DataWarehouse - edition. - + When source subscription belongs to a different tenant than target subscription, “x-ms-authorization-auxiliary” header must contain authentication token for the source tenant. For more details about “x-ms-authorization-auxiliary” header see https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/authenticate-multi-tenant. :paramtype source_resource_id: str """ - super(Database, self).__init__(location=location, tags=tags, **kwargs) + super().__init__(location=location, tags=tags, **kwargs) self.sku = sku self.kind = None self.managed_by = None @@ -1270,48 +1217,43 @@ class DatabaseAdvancedThreatProtection(ProxyResource): :vartype system_data: ~azure.mgmt.sql.models.SystemData :ivar state: Specifies the state of the Advanced Threat Protection, whether it is enabled or disabled or a state has not been applied yet on the specific database or server. Known values - are: "New", "Enabled", "Disabled". + are: "New", "Enabled", and "Disabled". :vartype state: str or ~azure.mgmt.sql.models.AdvancedThreatProtectionState :ivar creation_time: Specifies the UTC creation time of the policy. :vartype creation_time: ~datetime.datetime """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'system_data': {'readonly': True}, - 'creation_time': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "system_data": {"readonly": True}, + "creation_time": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'system_data': {'key': 'systemData', 'type': 'SystemData'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'creation_time': {'key': 'properties.creationTime', 'type': 'iso-8601'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "system_data": {"key": "systemData", "type": "SystemData"}, + "state": {"key": "properties.state", "type": "str"}, + "creation_time": {"key": "properties.creationTime", "type": "iso-8601"}, } - def __init__( - self, - *, - state: Optional[Union[str, "_models.AdvancedThreatProtectionState"]] = None, - **kwargs - ): + def __init__(self, *, state: Optional[Union[str, "_models.AdvancedThreatProtectionState"]] = None, **kwargs): """ :keyword state: Specifies the state of the Advanced Threat Protection, whether it is enabled or disabled or a state has not been applied yet on the specific database or server. Known values - are: "New", "Enabled", "Disabled". + are: "New", "Enabled", and "Disabled". :paramtype state: str or ~azure.mgmt.sql.models.AdvancedThreatProtectionState """ - super(DatabaseAdvancedThreatProtection, self).__init__(**kwargs) + super().__init__(**kwargs) self.system_data = None self.state = state self.creation_time = None -class DatabaseAdvancedThreatProtectionListResult(msrest.serialization.Model): +class DatabaseAdvancedThreatProtectionListResult(_serialization.Model): """A list of the database's Advanced Threat Protection configurations. Variables are only populated by the server, and will be ignored when sending a request. @@ -1323,22 +1265,18 @@ class DatabaseAdvancedThreatProtectionListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[DatabaseAdvancedThreatProtection]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[DatabaseAdvancedThreatProtection]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DatabaseAdvancedThreatProtectionListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -1355,29 +1293,29 @@ class DatabaseAutomaticTuning(ProxyResource): :ivar type: Resource type. :vartype type: str :ivar desired_state: Automatic tuning desired state. Known values are: "Inherit", "Custom", - "Auto", "Unspecified". + "Auto", and "Unspecified". :vartype desired_state: str or ~azure.mgmt.sql.models.AutomaticTuningMode :ivar actual_state: Automatic tuning actual state. Known values are: "Inherit", "Custom", - "Auto", "Unspecified". + "Auto", and "Unspecified". :vartype actual_state: str or ~azure.mgmt.sql.models.AutomaticTuningMode :ivar options: Automatic tuning options definition. :vartype options: dict[str, ~azure.mgmt.sql.models.AutomaticTuningOptions] """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'actual_state': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "actual_state": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'desired_state': {'key': 'properties.desiredState', 'type': 'str'}, - 'actual_state': {'key': 'properties.actualState', 'type': 'str'}, - 'options': {'key': 'properties.options', 'type': '{AutomaticTuningOptions}'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "desired_state": {"key": "properties.desiredState", "type": "str"}, + "actual_state": {"key": "properties.actualState", "type": "str"}, + "options": {"key": "properties.options", "type": "{AutomaticTuningOptions}"}, } def __init__( @@ -1389,18 +1327,18 @@ def __init__( ): """ :keyword desired_state: Automatic tuning desired state. Known values are: "Inherit", "Custom", - "Auto", "Unspecified". + "Auto", and "Unspecified". :paramtype desired_state: str or ~azure.mgmt.sql.models.AutomaticTuningMode :keyword options: Automatic tuning options definition. :paramtype options: dict[str, ~azure.mgmt.sql.models.AutomaticTuningOptions] """ - super(DatabaseAutomaticTuning, self).__init__(**kwargs) + super().__init__(**kwargs) self.desired_state = desired_state self.actual_state = None self.options = options -class DatabaseBlobAuditingPolicy(ProxyResource): +class DatabaseBlobAuditingPolicy(ProxyResource): # pylint: disable=too-many-instance-attributes """A database blob auditing policy. Variables are only populated by the server, and will be ignored when sending a request. @@ -1417,21 +1355,21 @@ class DatabaseBlobAuditingPolicy(ProxyResource): account. :vartype retention_days: int :ivar audit_actions_and_groups: Specifies the Actions-Groups and Actions to audit. - + The recommended set of action groups to use is the following combination - this will audit all the queries and stored procedures executed against the database, as well as successful and failed logins: - + BATCH_COMPLETED_GROUP, SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP, FAILED_DATABASE_AUTHENTICATION_GROUP. - + This above combination is also the set that is configured by default when enabling auditing from the Azure portal. - + The supported action groups to audit are (note: choose only specific groups that cover your auditing needs. Using unnecessary groups could lead to very large quantities of audit records): - + APPLICATION_ROLE_CHANGE_PASSWORD_GROUP BACKUP_RESTORE_GROUP DATABASE_LOGOUT_GROUP @@ -1456,14 +1394,14 @@ class DatabaseBlobAuditingPolicy(ProxyResource): DATABASE_OWNERSHIP_CHANGE_GROUP DATABASE_CHANGE_GROUP LEDGER_OPERATION_GROUP - + These are groups that cover all sql statements and stored procedures executed against the database, and should not be used in combination with other groups as this will result in duplicate audit logs. - + For more information, see `Database-Level Audit Action Groups `_. - + For Database auditing policy, specific Actions can also be specified (note that Actions cannot be specified for Server auditing policy). The supported actions to audit are: SELECT @@ -1473,19 +1411,19 @@ class DatabaseBlobAuditingPolicy(ProxyResource): EXECUTE RECEIVE REFERENCES - + The general form for defining an action to be audited is: {action} ON {object} BY {principal} - + Note that :code:`` in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE::{db_name} and SCHEMA::{schema_name} are used, respectively. - + For example: SELECT on dbo.myTable by public SELECT on DATABASE::myDatabase by public SELECT on SCHEMA::mySchema by public - + For more information, see `Database-Level Audit Actions `_. :vartype audit_actions_and_groups: list[str] @@ -1496,15 +1434,15 @@ class DatabaseBlobAuditingPolicy(ProxyResource): Monitor. In order to send the events to Azure Monitor, specify 'State' as 'Enabled' and 'IsAzureMonitorTargetEnabled' as true. - + When using REST API to configure auditing, Diagnostic Settings with 'SQLSecurityAuditEvents' diagnostic logs category on the database should be also created. Note that for server level audit you should use the 'master' database as {databaseName}. - + Diagnostic Settings URI format: PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview - + For more information, see `Diagnostic Settings REST API `_ or `Diagnostic Settings PowerShell `_. @@ -1517,7 +1455,7 @@ class DatabaseBlobAuditingPolicy(ProxyResource): storage. :vartype is_managed_identity_in_use: bool :ivar state: Specifies the state of the audit. If state is Enabled, storageEndpoint or - isAzureMonitorTargetEnabled are required. Known values are: "Enabled", "Disabled". + isAzureMonitorTargetEnabled are required. Known values are: "Enabled" and "Disabled". :vartype state: str or ~azure.mgmt.sql.models.BlobAuditingPolicyState :ivar storage_endpoint: Specifies the blob storage endpoint (e.g. https://MyAccount.blob.core.windows.net). If state is Enabled, storageEndpoint or @@ -1528,8 +1466,8 @@ class DatabaseBlobAuditingPolicy(ProxyResource): storageAccountAccessKey will use SQL server system-assigned managed identity to access the storage. Prerequisites for using managed identity authentication: - - + + #. Assign SQL Server a system-assigned managed identity in Azure Active Directory (AAD). #. Grant SQL Server identity access to the storage account by adding 'Storage Blob Data Contributor' RBAC role to the server identity. @@ -1541,27 +1479,27 @@ class DatabaseBlobAuditingPolicy(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'kind': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "kind": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'kind': {'key': 'kind', 'type': 'str'}, - 'retention_days': {'key': 'properties.retentionDays', 'type': 'int'}, - 'audit_actions_and_groups': {'key': 'properties.auditActionsAndGroups', 'type': '[str]'}, - 'is_storage_secondary_key_in_use': {'key': 'properties.isStorageSecondaryKeyInUse', 'type': 'bool'}, - 'is_azure_monitor_target_enabled': {'key': 'properties.isAzureMonitorTargetEnabled', 'type': 'bool'}, - 'queue_delay_ms': {'key': 'properties.queueDelayMs', 'type': 'int'}, - 'is_managed_identity_in_use': {'key': 'properties.isManagedIdentityInUse', 'type': 'bool'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'storage_endpoint': {'key': 'properties.storageEndpoint', 'type': 'str'}, - 'storage_account_access_key': {'key': 'properties.storageAccountAccessKey', 'type': 'str'}, - 'storage_account_subscription_id': {'key': 'properties.storageAccountSubscriptionId', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "kind": {"key": "kind", "type": "str"}, + "retention_days": {"key": "properties.retentionDays", "type": "int"}, + "audit_actions_and_groups": {"key": "properties.auditActionsAndGroups", "type": "[str]"}, + "is_storage_secondary_key_in_use": {"key": "properties.isStorageSecondaryKeyInUse", "type": "bool"}, + "is_azure_monitor_target_enabled": {"key": "properties.isAzureMonitorTargetEnabled", "type": "bool"}, + "queue_delay_ms": {"key": "properties.queueDelayMs", "type": "int"}, + "is_managed_identity_in_use": {"key": "properties.isManagedIdentityInUse", "type": "bool"}, + "state": {"key": "properties.state", "type": "str"}, + "storage_endpoint": {"key": "properties.storageEndpoint", "type": "str"}, + "storage_account_access_key": {"key": "properties.storageAccountAccessKey", "type": "str"}, + "storage_account_subscription_id": {"key": "properties.storageAccountSubscriptionId", "type": "str"}, } def __init__( @@ -1584,21 +1522,21 @@ def __init__( account. :paramtype retention_days: int :keyword audit_actions_and_groups: Specifies the Actions-Groups and Actions to audit. - + The recommended set of action groups to use is the following combination - this will audit all the queries and stored procedures executed against the database, as well as successful and failed logins: - + BATCH_COMPLETED_GROUP, SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP, FAILED_DATABASE_AUTHENTICATION_GROUP. - + This above combination is also the set that is configured by default when enabling auditing from the Azure portal. - + The supported action groups to audit are (note: choose only specific groups that cover your auditing needs. Using unnecessary groups could lead to very large quantities of audit records): - + APPLICATION_ROLE_CHANGE_PASSWORD_GROUP BACKUP_RESTORE_GROUP DATABASE_LOGOUT_GROUP @@ -1623,14 +1561,14 @@ def __init__( DATABASE_OWNERSHIP_CHANGE_GROUP DATABASE_CHANGE_GROUP LEDGER_OPERATION_GROUP - + These are groups that cover all sql statements and stored procedures executed against the database, and should not be used in combination with other groups as this will result in duplicate audit logs. - + For more information, see `Database-Level Audit Action Groups `_. - + For Database auditing policy, specific Actions can also be specified (note that Actions cannot be specified for Server auditing policy). The supported actions to audit are: SELECT @@ -1640,19 +1578,19 @@ def __init__( EXECUTE RECEIVE REFERENCES - + The general form for defining an action to be audited is: {action} ON {object} BY {principal} - + Note that :code:`` in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE::{db_name} and SCHEMA::{schema_name} are used, respectively. - + For example: SELECT on dbo.myTable by public SELECT on DATABASE::myDatabase by public SELECT on SCHEMA::mySchema by public - + For more information, see `Database-Level Audit Actions `_. :paramtype audit_actions_and_groups: list[str] @@ -1663,15 +1601,15 @@ def __init__( Monitor. In order to send the events to Azure Monitor, specify 'State' as 'Enabled' and 'IsAzureMonitorTargetEnabled' as true. - + When using REST API to configure auditing, Diagnostic Settings with 'SQLSecurityAuditEvents' diagnostic logs category on the database should be also created. Note that for server level audit you should use the 'master' database as {databaseName}. - + Diagnostic Settings URI format: PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview - + For more information, see `Diagnostic Settings REST API `_ or `Diagnostic Settings PowerShell `_. @@ -1684,7 +1622,7 @@ def __init__( storage. :paramtype is_managed_identity_in_use: bool :keyword state: Specifies the state of the audit. If state is Enabled, storageEndpoint or - isAzureMonitorTargetEnabled are required. Known values are: "Enabled", "Disabled". + isAzureMonitorTargetEnabled are required. Known values are: "Enabled" and "Disabled". :paramtype state: str or ~azure.mgmt.sql.models.BlobAuditingPolicyState :keyword storage_endpoint: Specifies the blob storage endpoint (e.g. https://MyAccount.blob.core.windows.net). If state is Enabled, storageEndpoint or @@ -1696,8 +1634,8 @@ def __init__( storageAccountAccessKey will use SQL server system-assigned managed identity to access the storage. Prerequisites for using managed identity authentication: - - + + #. Assign SQL Server a system-assigned managed identity in Azure Active Directory (AAD). #. Grant SQL Server identity access to the storage account by adding 'Storage Blob Data Contributor' RBAC role to the server identity. @@ -1707,7 +1645,7 @@ def __init__( :keyword storage_account_subscription_id: Specifies the blob storage subscription Id. :paramtype storage_account_subscription_id: str """ - super(DatabaseBlobAuditingPolicy, self).__init__(**kwargs) + super().__init__(**kwargs) self.kind = None self.retention_days = retention_days self.audit_actions_and_groups = audit_actions_and_groups @@ -1721,7 +1659,7 @@ def __init__( self.storage_account_subscription_id = storage_account_subscription_id -class DatabaseBlobAuditingPolicyListResult(msrest.serialization.Model): +class DatabaseBlobAuditingPolicyListResult(_serialization.Model): """A list of database auditing settings. Variables are only populated by the server, and will be ignored when sending a request. @@ -1733,22 +1671,18 @@ class DatabaseBlobAuditingPolicyListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[DatabaseBlobAuditingPolicy]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[DatabaseBlobAuditingPolicy]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DatabaseBlobAuditingPolicyListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -1768,10 +1702,10 @@ class DatabaseColumn(ProxyResource): "date", "time", "datetime2", "datetimeoffset", "tinyint", "smallint", "int", "smalldatetime", "real", "money", "datetime", "float", "sql_variant", "ntext", "bit", "decimal", "numeric", "smallmoney", "bigint", "hierarchyid", "geometry", "geography", "varbinary", "varchar", - "binary", "char", "timestamp", "nvarchar", "nchar", "xml", "sysname". + "binary", "char", "timestamp", "nvarchar", "nchar", "xml", and "sysname". :vartype column_type: str or ~azure.mgmt.sql.models.ColumnDataType :ivar temporal_type: The table temporal type. Known values are: "NonTemporalTable", - "HistoryTable", "SystemVersionedTemporalTable". + "HistoryTable", and "SystemVersionedTemporalTable". :vartype temporal_type: str or ~azure.mgmt.sql.models.TableTemporalType :ivar memory_optimized: Whether or not the column belongs to a memory optimized table. :vartype memory_optimized: bool @@ -1780,19 +1714,19 @@ class DatabaseColumn(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'column_type': {'key': 'properties.columnType', 'type': 'str'}, - 'temporal_type': {'key': 'properties.temporalType', 'type': 'str'}, - 'memory_optimized': {'key': 'properties.memoryOptimized', 'type': 'bool'}, - 'is_computed': {'key': 'properties.isComputed', 'type': 'bool'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "column_type": {"key": "properties.columnType", "type": "str"}, + "temporal_type": {"key": "properties.temporalType", "type": "str"}, + "memory_optimized": {"key": "properties.memoryOptimized", "type": "bool"}, + "is_computed": {"key": "properties.isComputed", "type": "bool"}, } def __init__( @@ -1809,24 +1743,25 @@ def __init__( "uniqueidentifier", "date", "time", "datetime2", "datetimeoffset", "tinyint", "smallint", "int", "smalldatetime", "real", "money", "datetime", "float", "sql_variant", "ntext", "bit", "decimal", "numeric", "smallmoney", "bigint", "hierarchyid", "geometry", "geography", - "varbinary", "varchar", "binary", "char", "timestamp", "nvarchar", "nchar", "xml", "sysname". + "varbinary", "varchar", "binary", "char", "timestamp", "nvarchar", "nchar", "xml", and + "sysname". :paramtype column_type: str or ~azure.mgmt.sql.models.ColumnDataType :keyword temporal_type: The table temporal type. Known values are: "NonTemporalTable", - "HistoryTable", "SystemVersionedTemporalTable". + "HistoryTable", and "SystemVersionedTemporalTable". :paramtype temporal_type: str or ~azure.mgmt.sql.models.TableTemporalType :keyword memory_optimized: Whether or not the column belongs to a memory optimized table. :paramtype memory_optimized: bool :keyword is_computed: Whether or not the column is computed. :paramtype is_computed: bool """ - super(DatabaseColumn, self).__init__(**kwargs) + super().__init__(**kwargs) self.column_type = column_type self.temporal_type = temporal_type self.memory_optimized = memory_optimized self.is_computed = is_computed -class DatabaseColumnListResult(msrest.serialization.Model): +class DatabaseColumnListResult(_serialization.Model): """A list of database columns. Variables are only populated by the server, and will be ignored when sending a request. @@ -1838,22 +1773,18 @@ class DatabaseColumnListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[DatabaseColumn]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[DatabaseColumn]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DatabaseColumnListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -1869,9 +1800,9 @@ class DatabaseExtensions(ProxyResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar operation_mode: Operation Mode. Known values are: "PolybaseImport". + :ivar operation_mode: Operation Mode. "PolybaseImport" :vartype operation_mode: str or ~azure.mgmt.sql.models.OperationMode - :ivar storage_key_type: Storage key type. Known values are: "SharedAccessKey", + :ivar storage_key_type: Storage key type. Known values are: "SharedAccessKey" and "StorageAccessKey". :vartype storage_key_type: str or ~azure.mgmt.sql.models.StorageKeyType :ivar storage_key: Storage key. @@ -1881,19 +1812,19 @@ class DatabaseExtensions(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'operation_mode': {'key': 'properties.operationMode', 'type': 'str'}, - 'storage_key_type': {'key': 'properties.storageKeyType', 'type': 'str'}, - 'storage_key': {'key': 'properties.storageKey', 'type': 'str'}, - 'storage_uri': {'key': 'properties.storageUri', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "operation_mode": {"key": "properties.operationMode", "type": "str"}, + "storage_key_type": {"key": "properties.storageKeyType", "type": "str"}, + "storage_key": {"key": "properties.storageKey", "type": "str"}, + "storage_uri": {"key": "properties.storageUri", "type": "str"}, } def __init__( @@ -1906,9 +1837,9 @@ def __init__( **kwargs ): """ - :keyword operation_mode: Operation Mode. Known values are: "PolybaseImport". + :keyword operation_mode: Operation Mode. "PolybaseImport" :paramtype operation_mode: str or ~azure.mgmt.sql.models.OperationMode - :keyword storage_key_type: Storage key type. Known values are: "SharedAccessKey", + :keyword storage_key_type: Storage key type. Known values are: "SharedAccessKey" and "StorageAccessKey". :paramtype storage_key_type: str or ~azure.mgmt.sql.models.StorageKeyType :keyword storage_key: Storage key. @@ -1916,19 +1847,19 @@ def __init__( :keyword storage_uri: Storage Uri. :paramtype storage_uri: str """ - super(DatabaseExtensions, self).__init__(**kwargs) + super().__init__(**kwargs) self.operation_mode = operation_mode self.storage_key_type = storage_key_type self.storage_key = storage_key self.storage_uri = storage_uri -class DatabaseIdentity(msrest.serialization.Model): +class DatabaseIdentity(_serialization.Model): """Azure Active Directory identity configuration for a resource. Variables are only populated by the server, and will be ignored when sending a request. - :ivar type: The identity type. Known values are: "None", "UserAssigned". + :ivar type: The identity type. Known values are: "None" and "UserAssigned". :vartype type: str or ~azure.mgmt.sql.models.DatabaseIdentityType :ivar tenant_id: The Azure Active Directory tenant id. :vartype tenant_id: str @@ -1937,13 +1868,13 @@ class DatabaseIdentity(msrest.serialization.Model): """ _validation = { - 'tenant_id': {'readonly': True}, + "tenant_id": {"readonly": True}, } _attribute_map = { - 'type': {'key': 'type', 'type': 'str'}, - 'tenant_id': {'key': 'tenantId', 'type': 'str'}, - 'user_assigned_identities': {'key': 'userAssignedIdentities', 'type': '{DatabaseUserIdentity}'}, + "type": {"key": "type", "type": "str"}, + "tenant_id": {"key": "tenantId", "type": "str"}, + "user_assigned_identities": {"key": "userAssignedIdentities", "type": "{DatabaseUserIdentity}"}, } def __init__( @@ -1954,18 +1885,18 @@ def __init__( **kwargs ): """ - :keyword type: The identity type. Known values are: "None", "UserAssigned". + :keyword type: The identity type. Known values are: "None" and "UserAssigned". :paramtype type: str or ~azure.mgmt.sql.models.DatabaseIdentityType :keyword user_assigned_identities: The resource ids of the user assigned identities to use. :paramtype user_assigned_identities: dict[str, ~azure.mgmt.sql.models.DatabaseUserIdentity] """ - super(DatabaseIdentity, self).__init__(**kwargs) + super().__init__(**kwargs) self.type = type self.tenant_id = None self.user_assigned_identities = user_assigned_identities -class DatabaseListResult(msrest.serialization.Model): +class DatabaseListResult(_serialization.Model): """A list of databases. Variables are only populated by the server, and will be ignored when sending a request. @@ -1977,27 +1908,23 @@ class DatabaseListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[Database]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[Database]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DatabaseListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class DatabaseOperation(ProxyResource): +class DatabaseOperation(ProxyResource): # pylint: disable=too-many-instance-attributes """A database operation. Variables are only populated by the server, and will be ignored when sending a request. @@ -2021,7 +1948,7 @@ class DatabaseOperation(ProxyResource): :ivar start_time: The operation start time. :vartype start_time: ~datetime.datetime :ivar state: The operation state. Known values are: "Pending", "InProgress", "Succeeded", - "Failed", "CancelInProgress", "Cancelled". + "Failed", "CancelInProgress", and "Cancelled". :vartype state: str or ~azure.mgmt.sql.models.ManagementOperationState :ivar error_code: The operation error code. :vartype error_code: int @@ -2040,52 +1967,48 @@ class DatabaseOperation(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'database_name': {'readonly': True}, - 'operation': {'readonly': True}, - 'operation_friendly_name': {'readonly': True}, - 'percent_complete': {'readonly': True}, - 'server_name': {'readonly': True}, - 'start_time': {'readonly': True}, - 'state': {'readonly': True}, - 'error_code': {'readonly': True}, - 'error_description': {'readonly': True}, - 'error_severity': {'readonly': True}, - 'is_user_error': {'readonly': True}, - 'estimated_completion_time': {'readonly': True}, - 'description': {'readonly': True}, - 'is_cancellable': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'database_name': {'key': 'properties.databaseName', 'type': 'str'}, - 'operation': {'key': 'properties.operation', 'type': 'str'}, - 'operation_friendly_name': {'key': 'properties.operationFriendlyName', 'type': 'str'}, - 'percent_complete': {'key': 'properties.percentComplete', 'type': 'int'}, - 'server_name': {'key': 'properties.serverName', 'type': 'str'}, - 'start_time': {'key': 'properties.startTime', 'type': 'iso-8601'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'error_code': {'key': 'properties.errorCode', 'type': 'int'}, - 'error_description': {'key': 'properties.errorDescription', 'type': 'str'}, - 'error_severity': {'key': 'properties.errorSeverity', 'type': 'int'}, - 'is_user_error': {'key': 'properties.isUserError', 'type': 'bool'}, - 'estimated_completion_time': {'key': 'properties.estimatedCompletionTime', 'type': 'iso-8601'}, - 'description': {'key': 'properties.description', 'type': 'str'}, - 'is_cancellable': {'key': 'properties.isCancellable', 'type': 'bool'}, - } - - def __init__( - self, - **kwargs - ): - """ - """ - super(DatabaseOperation, self).__init__(**kwargs) + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "database_name": {"readonly": True}, + "operation": {"readonly": True}, + "operation_friendly_name": {"readonly": True}, + "percent_complete": {"readonly": True}, + "server_name": {"readonly": True}, + "start_time": {"readonly": True}, + "state": {"readonly": True}, + "error_code": {"readonly": True}, + "error_description": {"readonly": True}, + "error_severity": {"readonly": True}, + "is_user_error": {"readonly": True}, + "estimated_completion_time": {"readonly": True}, + "description": {"readonly": True}, + "is_cancellable": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "database_name": {"key": "properties.databaseName", "type": "str"}, + "operation": {"key": "properties.operation", "type": "str"}, + "operation_friendly_name": {"key": "properties.operationFriendlyName", "type": "str"}, + "percent_complete": {"key": "properties.percentComplete", "type": "int"}, + "server_name": {"key": "properties.serverName", "type": "str"}, + "start_time": {"key": "properties.startTime", "type": "iso-8601"}, + "state": {"key": "properties.state", "type": "str"}, + "error_code": {"key": "properties.errorCode", "type": "int"}, + "error_description": {"key": "properties.errorDescription", "type": "str"}, + "error_severity": {"key": "properties.errorSeverity", "type": "int"}, + "is_user_error": {"key": "properties.isUserError", "type": "bool"}, + "estimated_completion_time": {"key": "properties.estimatedCompletionTime", "type": "iso-8601"}, + "description": {"key": "properties.description", "type": "str"}, + "is_cancellable": {"key": "properties.isCancellable", "type": "bool"}, + } + + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.database_name = None self.operation = None self.operation_friendly_name = None @@ -2102,7 +2025,7 @@ def __init__( self.is_cancellable = None -class DatabaseOperationListResult(msrest.serialization.Model): +class DatabaseOperationListResult(_serialization.Model): """The response to a list database operations request. Variables are only populated by the server, and will be ignored when sending a request. @@ -2114,22 +2037,18 @@ class DatabaseOperationListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[DatabaseOperation]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[DatabaseOperation]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DatabaseOperationListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -2148,27 +2067,23 @@ class DatabaseSchema(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DatabaseSchema, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) -class DatabaseSchemaListResult(msrest.serialization.Model): +class DatabaseSchemaListResult(_serialization.Model): """A list of database schemas. Variables are only populated by the server, and will be ignored when sending a request. @@ -2180,27 +2095,23 @@ class DatabaseSchemaListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[DatabaseSchema]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[DatabaseSchema]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DatabaseSchemaListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class DatabaseSecurityAlertListResult(msrest.serialization.Model): +class DatabaseSecurityAlertListResult(_serialization.Model): """A list of the database's security alert policies. Variables are only populated by the server, and will be ignored when sending a request. @@ -2212,27 +2123,23 @@ class DatabaseSecurityAlertListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[DatabaseSecurityAlertPolicy]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[DatabaseSecurityAlertPolicy]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DatabaseSecurityAlertListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class DatabaseSecurityAlertPolicy(ProxyResource): +class DatabaseSecurityAlertPolicy(ProxyResource): # pylint: disable=too-many-instance-attributes """A database security alert policy. Variables are only populated by the server, and will be ignored when sending a request. @@ -2246,7 +2153,7 @@ class DatabaseSecurityAlertPolicy(ProxyResource): :ivar system_data: SystemData of SecurityAlertPolicyResource. :vartype system_data: ~azure.mgmt.sql.models.SystemData :ivar state: Specifies the state of the policy, whether it is enabled or disabled or a policy - has not been applied yet on the specific database. Known values are: "Enabled", "Disabled". + has not been applied yet on the specific database. Known values are: "Enabled" and "Disabled". :vartype state: str or ~azure.mgmt.sql.models.SecurityAlertsPolicyState :ivar disabled_alerts: Specifies an array of alerts that are disabled. Allowed values are: Sql_Injection, Sql_Injection_Vulnerability, Access_Anomaly, Data_Exfiltration, Unsafe_Action, @@ -2270,26 +2177,26 @@ class DatabaseSecurityAlertPolicy(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'system_data': {'readonly': True}, - 'creation_time': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "system_data": {"readonly": True}, + "creation_time": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'system_data': {'key': 'systemData', 'type': 'SystemData'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'disabled_alerts': {'key': 'properties.disabledAlerts', 'type': '[str]'}, - 'email_addresses': {'key': 'properties.emailAddresses', 'type': '[str]'}, - 'email_account_admins': {'key': 'properties.emailAccountAdmins', 'type': 'bool'}, - 'storage_endpoint': {'key': 'properties.storageEndpoint', 'type': 'str'}, - 'storage_account_access_key': {'key': 'properties.storageAccountAccessKey', 'type': 'str'}, - 'retention_days': {'key': 'properties.retentionDays', 'type': 'int'}, - 'creation_time': {'key': 'properties.creationTime', 'type': 'iso-8601'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "system_data": {"key": "systemData", "type": "SystemData"}, + "state": {"key": "properties.state", "type": "str"}, + "disabled_alerts": {"key": "properties.disabledAlerts", "type": "[str]"}, + "email_addresses": {"key": "properties.emailAddresses", "type": "[str]"}, + "email_account_admins": {"key": "properties.emailAccountAdmins", "type": "bool"}, + "storage_endpoint": {"key": "properties.storageEndpoint", "type": "str"}, + "storage_account_access_key": {"key": "properties.storageAccountAccessKey", "type": "str"}, + "retention_days": {"key": "properties.retentionDays", "type": "int"}, + "creation_time": {"key": "properties.creationTime", "type": "iso-8601"}, } def __init__( @@ -2306,7 +2213,7 @@ def __init__( ): """ :keyword state: Specifies the state of the policy, whether it is enabled or disabled or a - policy has not been applied yet on the specific database. Known values are: "Enabled", + policy has not been applied yet on the specific database. Known values are: "Enabled" and "Disabled". :paramtype state: str or ~azure.mgmt.sql.models.SecurityAlertsPolicyState :keyword disabled_alerts: Specifies an array of alerts that are disabled. Allowed values are: @@ -2328,7 +2235,7 @@ def __init__( logs. :paramtype retention_days: int """ - super(DatabaseSecurityAlertPolicy, self).__init__(**kwargs) + super().__init__(**kwargs) self.system_data = None self.state = state self.disabled_alerts = disabled_alerts @@ -2352,24 +2259,24 @@ class DatabaseTable(ProxyResource): :ivar type: Resource type. :vartype type: str :ivar temporal_type: The table temporal type. Known values are: "NonTemporalTable", - "HistoryTable", "SystemVersionedTemporalTable". + "HistoryTable", and "SystemVersionedTemporalTable". :vartype temporal_type: str or ~azure.mgmt.sql.models.TableTemporalType :ivar memory_optimized: Whether or not the table is memory optimized. :vartype memory_optimized: bool """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'temporal_type': {'key': 'properties.temporalType', 'type': 'str'}, - 'memory_optimized': {'key': 'properties.memoryOptimized', 'type': 'bool'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "temporal_type": {"key": "properties.temporalType", "type": "str"}, + "memory_optimized": {"key": "properties.memoryOptimized", "type": "bool"}, } def __init__( @@ -2381,17 +2288,17 @@ def __init__( ): """ :keyword temporal_type: The table temporal type. Known values are: "NonTemporalTable", - "HistoryTable", "SystemVersionedTemporalTable". + "HistoryTable", and "SystemVersionedTemporalTable". :paramtype temporal_type: str or ~azure.mgmt.sql.models.TableTemporalType :keyword memory_optimized: Whether or not the table is memory optimized. :paramtype memory_optimized: bool """ - super(DatabaseTable, self).__init__(**kwargs) + super().__init__(**kwargs) self.temporal_type = temporal_type self.memory_optimized = memory_optimized -class DatabaseTableListResult(msrest.serialization.Model): +class DatabaseTableListResult(_serialization.Model): """A list of database tables. Variables are only populated by the server, and will be ignored when sending a request. @@ -2403,27 +2310,23 @@ class DatabaseTableListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[DatabaseTable]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[DatabaseTable]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DatabaseTableListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class DatabaseUpdate(msrest.serialization.Model): +class DatabaseUpdate(_serialization.Model): # pylint: disable=too-many-instance-attributes """A database update resource. Variables are only populated by the server, and will be ignored when sending a request. @@ -2432,46 +2335,46 @@ class DatabaseUpdate(msrest.serialization.Model): :vartype sku: ~azure.mgmt.sql.models.Sku :ivar identity: Database identity. :vartype identity: ~azure.mgmt.sql.models.DatabaseIdentity - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar create_mode: Specifies the mode of database creation. - + Default: regular database creation. - + Copy: creates a database as a copy of an existing database. sourceDatabaseId must be specified as the resource ID of the source database. - + Secondary: creates a database as a secondary replica of an existing database. sourceDatabaseId must be specified as the resource ID of the existing primary database. - + PointInTimeRestore: Creates a database by restoring a point in time backup of an existing database. sourceDatabaseId must be specified as the resource ID of the existing database, and restorePointInTime must be specified. - + Recovery: Creates a database by restoring a geo-replicated backup. sourceDatabaseId must be specified as the recoverable database resource ID to restore. - + Restore: Creates a database by restoring a backup of a deleted database. sourceDatabaseId must be specified. If sourceDatabaseId is the database's original resource ID, then sourceDatabaseDeletionDate must be specified. Otherwise sourceDatabaseId must be the restorable dropped database resource ID and sourceDatabaseDeletionDate is ignored. restorePointInTime may also be specified to restore from an earlier point in time. - + RestoreLongTermRetentionBackup: Creates a database by restoring from a long term retention vault. recoveryServicesRecoveryPointResourceId must be specified as the recovery point resource ID. - + Copy, Secondary, and RestoreLongTermRetentionBackup are not supported for DataWarehouse edition. Known values are: "Default", "Copy", "Secondary", "PointInTimeRestore", "Restore", "Recovery", "RestoreExternalBackup", "RestoreExternalBackupSecondary", - "RestoreLongTermRetentionBackup", "OnlineSecondary". + "RestoreLongTermRetentionBackup", and "OnlineSecondary". :vartype create_mode: str or ~azure.mgmt.sql.models.CreateMode :ivar collation: The collation of the database. :vartype collation: str :ivar max_size_bytes: The max size of the database expressed in bytes. - :vartype max_size_bytes: long + :vartype max_size_bytes: int :ivar sample_name: The name of the sample schema to apply when creating this database. Known - values are: "AdventureWorksLT", "WideWorldImportersStd", "WideWorldImportersFull". + values are: "AdventureWorksLT", "WideWorldImportersStd", and "WideWorldImportersFull". :vartype sample_name: str or ~azure.mgmt.sql.models.SampleName :ivar elastic_pool_id: The resource identifier of the elastic pool containing this database. :vartype elastic_pool_id: str @@ -2482,7 +2385,7 @@ class DatabaseUpdate(msrest.serialization.Model): "RecoveryPending", "Recovering", "Suspect", "Offline", "Standby", "Shutdown", "EmergencyMode", "AutoClosed", "Copying", "Creating", "Inaccessible", "OfflineSecondary", "Pausing", "Paused", "Resuming", "Scaling", "OfflineChangingDwPerformanceTiers", "OnlineChangingDwPerformanceTiers", - "Disabled", "Stopping", "Stopped", "Starting". + "Disabled", "Stopping", "Stopped", and "Starting". :vartype status: str or ~azure.mgmt.sql.models.DatabaseStatus :ivar database_id: The ID of the database. :vartype database_id: str @@ -2515,31 +2418,31 @@ class DatabaseUpdate(msrest.serialization.Model): database associated with create operation of this database. :vartype restorable_dropped_database_id: str :ivar catalog_collation: Collation of the metadata catalog. Known values are: - "DATABASE_DEFAULT", "SQL_Latin1_General_CP1_CI_AS". + "DATABASE_DEFAULT" and "SQL_Latin1_General_CP1_CI_AS". :vartype catalog_collation: str or ~azure.mgmt.sql.models.CatalogCollationType :ivar zone_redundant: Whether or not this database is zone redundant, which means the replicas of this database will be spread across multiple availability zones. :vartype zone_redundant: bool :ivar license_type: The license type to apply for this database. ``LicenseIncluded`` if you need a license, or ``BasePrice`` if you have a license and are eligible for the Azure Hybrid - Benefit. Known values are: "LicenseIncluded", "BasePrice". + Benefit. Known values are: "LicenseIncluded" and "BasePrice". :vartype license_type: str or ~azure.mgmt.sql.models.DatabaseLicenseType :ivar max_log_size_bytes: The max log size for this database. - :vartype max_log_size_bytes: long + :vartype max_log_size_bytes: int :ivar earliest_restore_date: This records the earliest start date and time that restore is available for this database (ISO8601 format). :vartype earliest_restore_date: ~datetime.datetime :ivar read_scale: The state of read-only routing. If enabled, connections that have application intent set to readonly in their connection string may be routed to a readonly secondary replica in the same region. Not applicable to a Hyperscale database within an elastic pool. Known - values are: "Enabled", "Disabled". + values are: "Enabled" and "Disabled". :vartype read_scale: str or ~azure.mgmt.sql.models.DatabaseReadScale :ivar high_availability_replica_count: The number of secondary replicas associated with the database that are used to provide high availability. Not applicable to a Hyperscale database within an elastic pool. :vartype high_availability_replica_count: int :ivar secondary_type: The secondary type of the database if it is a secondary. Valid values - are Geo and Named. Known values are: "Geo", "Named". + are Geo, Named and Standby. Known values are: "Geo", "Named", and "Standby". :vartype secondary_type: str or ~azure.mgmt.sql.models.SecondaryType :ivar current_sku: The name and tier of the SKU. :vartype current_sku: ~azure.mgmt.sql.models.Sku @@ -2547,11 +2450,11 @@ class DatabaseUpdate(msrest.serialization.Model): of -1 means that automatic pause is disabled. :vartype auto_pause_delay: int :ivar current_backup_storage_redundancy: The storage account type used to store backups for - this database. Known values are: "Geo", "Local", "Zone", "GeoZone". + this database. Known values are: "Geo", "Local", "Zone", and "GeoZone". :vartype current_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy :ivar requested_backup_storage_redundancy: The storage account type to be used to store backups - for this database. Known values are: "Geo", "Local", "Zone", "GeoZone". + for this database. Known values are: "Geo", "Local", "Zone", and "GeoZone". :vartype requested_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy :ivar min_capacity: Minimal capacity that database will always have allocated, if not paused. @@ -2576,67 +2479,70 @@ class DatabaseUpdate(msrest.serialization.Model): """ _validation = { - 'status': {'readonly': True}, - 'database_id': {'readonly': True}, - 'creation_date': {'readonly': True}, - 'current_service_objective_name': {'readonly': True}, - 'requested_service_objective_name': {'readonly': True}, - 'default_secondary_location': {'readonly': True}, - 'failover_group_id': {'readonly': True}, - 'max_log_size_bytes': {'readonly': True}, - 'earliest_restore_date': {'readonly': True}, - 'current_sku': {'readonly': True}, - 'current_backup_storage_redundancy': {'readonly': True}, - 'paused_date': {'readonly': True}, - 'resumed_date': {'readonly': True}, - 'is_infra_encryption_enabled': {'readonly': True}, - } - - _attribute_map = { - 'sku': {'key': 'sku', 'type': 'Sku'}, - 'identity': {'key': 'identity', 'type': 'DatabaseIdentity'}, - 'tags': {'key': 'tags', 'type': '{str}'}, - 'create_mode': {'key': 'properties.createMode', 'type': 'str'}, - 'collation': {'key': 'properties.collation', 'type': 'str'}, - 'max_size_bytes': {'key': 'properties.maxSizeBytes', 'type': 'long'}, - 'sample_name': {'key': 'properties.sampleName', 'type': 'str'}, - 'elastic_pool_id': {'key': 'properties.elasticPoolId', 'type': 'str'}, - 'source_database_id': {'key': 'properties.sourceDatabaseId', 'type': 'str'}, - 'status': {'key': 'properties.status', 'type': 'str'}, - 'database_id': {'key': 'properties.databaseId', 'type': 'str'}, - 'creation_date': {'key': 'properties.creationDate', 'type': 'iso-8601'}, - 'current_service_objective_name': {'key': 'properties.currentServiceObjectiveName', 'type': 'str'}, - 'requested_service_objective_name': {'key': 'properties.requestedServiceObjectiveName', 'type': 'str'}, - 'default_secondary_location': {'key': 'properties.defaultSecondaryLocation', 'type': 'str'}, - 'failover_group_id': {'key': 'properties.failoverGroupId', 'type': 'str'}, - 'restore_point_in_time': {'key': 'properties.restorePointInTime', 'type': 'iso-8601'}, - 'source_database_deletion_date': {'key': 'properties.sourceDatabaseDeletionDate', 'type': 'iso-8601'}, - 'recovery_services_recovery_point_id': {'key': 'properties.recoveryServicesRecoveryPointId', 'type': 'str'}, - 'long_term_retention_backup_resource_id': {'key': 'properties.longTermRetentionBackupResourceId', 'type': 'str'}, - 'recoverable_database_id': {'key': 'properties.recoverableDatabaseId', 'type': 'str'}, - 'restorable_dropped_database_id': {'key': 'properties.restorableDroppedDatabaseId', 'type': 'str'}, - 'catalog_collation': {'key': 'properties.catalogCollation', 'type': 'str'}, - 'zone_redundant': {'key': 'properties.zoneRedundant', 'type': 'bool'}, - 'license_type': {'key': 'properties.licenseType', 'type': 'str'}, - 'max_log_size_bytes': {'key': 'properties.maxLogSizeBytes', 'type': 'long'}, - 'earliest_restore_date': {'key': 'properties.earliestRestoreDate', 'type': 'iso-8601'}, - 'read_scale': {'key': 'properties.readScale', 'type': 'str'}, - 'high_availability_replica_count': {'key': 'properties.highAvailabilityReplicaCount', 'type': 'int'}, - 'secondary_type': {'key': 'properties.secondaryType', 'type': 'str'}, - 'current_sku': {'key': 'properties.currentSku', 'type': 'Sku'}, - 'auto_pause_delay': {'key': 'properties.autoPauseDelay', 'type': 'int'}, - 'current_backup_storage_redundancy': {'key': 'properties.currentBackupStorageRedundancy', 'type': 'str'}, - 'requested_backup_storage_redundancy': {'key': 'properties.requestedBackupStorageRedundancy', 'type': 'str'}, - 'min_capacity': {'key': 'properties.minCapacity', 'type': 'float'}, - 'paused_date': {'key': 'properties.pausedDate', 'type': 'iso-8601'}, - 'resumed_date': {'key': 'properties.resumedDate', 'type': 'iso-8601'}, - 'maintenance_configuration_id': {'key': 'properties.maintenanceConfigurationId', 'type': 'str'}, - 'is_ledger_on': {'key': 'properties.isLedgerOn', 'type': 'bool'}, - 'is_infra_encryption_enabled': {'key': 'properties.isInfraEncryptionEnabled', 'type': 'bool'}, - 'federated_client_id': {'key': 'properties.federatedClientId', 'type': 'str'}, - } - - def __init__( + "status": {"readonly": True}, + "database_id": {"readonly": True}, + "creation_date": {"readonly": True}, + "current_service_objective_name": {"readonly": True}, + "requested_service_objective_name": {"readonly": True}, + "default_secondary_location": {"readonly": True}, + "failover_group_id": {"readonly": True}, + "max_log_size_bytes": {"readonly": True}, + "earliest_restore_date": {"readonly": True}, + "current_sku": {"readonly": True}, + "current_backup_storage_redundancy": {"readonly": True}, + "paused_date": {"readonly": True}, + "resumed_date": {"readonly": True}, + "is_infra_encryption_enabled": {"readonly": True}, + } + + _attribute_map = { + "sku": {"key": "sku", "type": "Sku"}, + "identity": {"key": "identity", "type": "DatabaseIdentity"}, + "tags": {"key": "tags", "type": "{str}"}, + "create_mode": {"key": "properties.createMode", "type": "str"}, + "collation": {"key": "properties.collation", "type": "str"}, + "max_size_bytes": {"key": "properties.maxSizeBytes", "type": "int"}, + "sample_name": {"key": "properties.sampleName", "type": "str"}, + "elastic_pool_id": {"key": "properties.elasticPoolId", "type": "str"}, + "source_database_id": {"key": "properties.sourceDatabaseId", "type": "str"}, + "status": {"key": "properties.status", "type": "str"}, + "database_id": {"key": "properties.databaseId", "type": "str"}, + "creation_date": {"key": "properties.creationDate", "type": "iso-8601"}, + "current_service_objective_name": {"key": "properties.currentServiceObjectiveName", "type": "str"}, + "requested_service_objective_name": {"key": "properties.requestedServiceObjectiveName", "type": "str"}, + "default_secondary_location": {"key": "properties.defaultSecondaryLocation", "type": "str"}, + "failover_group_id": {"key": "properties.failoverGroupId", "type": "str"}, + "restore_point_in_time": {"key": "properties.restorePointInTime", "type": "iso-8601"}, + "source_database_deletion_date": {"key": "properties.sourceDatabaseDeletionDate", "type": "iso-8601"}, + "recovery_services_recovery_point_id": {"key": "properties.recoveryServicesRecoveryPointId", "type": "str"}, + "long_term_retention_backup_resource_id": { + "key": "properties.longTermRetentionBackupResourceId", + "type": "str", + }, + "recoverable_database_id": {"key": "properties.recoverableDatabaseId", "type": "str"}, + "restorable_dropped_database_id": {"key": "properties.restorableDroppedDatabaseId", "type": "str"}, + "catalog_collation": {"key": "properties.catalogCollation", "type": "str"}, + "zone_redundant": {"key": "properties.zoneRedundant", "type": "bool"}, + "license_type": {"key": "properties.licenseType", "type": "str"}, + "max_log_size_bytes": {"key": "properties.maxLogSizeBytes", "type": "int"}, + "earliest_restore_date": {"key": "properties.earliestRestoreDate", "type": "iso-8601"}, + "read_scale": {"key": "properties.readScale", "type": "str"}, + "high_availability_replica_count": {"key": "properties.highAvailabilityReplicaCount", "type": "int"}, + "secondary_type": {"key": "properties.secondaryType", "type": "str"}, + "current_sku": {"key": "properties.currentSku", "type": "Sku"}, + "auto_pause_delay": {"key": "properties.autoPauseDelay", "type": "int"}, + "current_backup_storage_redundancy": {"key": "properties.currentBackupStorageRedundancy", "type": "str"}, + "requested_backup_storage_redundancy": {"key": "properties.requestedBackupStorageRedundancy", "type": "str"}, + "min_capacity": {"key": "properties.minCapacity", "type": "float"}, + "paused_date": {"key": "properties.pausedDate", "type": "iso-8601"}, + "resumed_date": {"key": "properties.resumedDate", "type": "iso-8601"}, + "maintenance_configuration_id": {"key": "properties.maintenanceConfigurationId", "type": "str"}, + "is_ledger_on": {"key": "properties.isLedgerOn", "type": "bool"}, + "is_infra_encryption_enabled": {"key": "properties.isInfraEncryptionEnabled", "type": "bool"}, + "federated_client_id": {"key": "properties.federatedClientId", "type": "str"}, + } + + def __init__( # pylint: disable=too-many-locals self, *, sku: Optional["_models.Sku"] = None, @@ -2673,46 +2579,46 @@ def __init__( :paramtype sku: ~azure.mgmt.sql.models.Sku :keyword identity: Database identity. :paramtype identity: ~azure.mgmt.sql.models.DatabaseIdentity - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] :keyword create_mode: Specifies the mode of database creation. - + Default: regular database creation. - + Copy: creates a database as a copy of an existing database. sourceDatabaseId must be specified as the resource ID of the source database. - + Secondary: creates a database as a secondary replica of an existing database. sourceDatabaseId must be specified as the resource ID of the existing primary database. - + PointInTimeRestore: Creates a database by restoring a point in time backup of an existing database. sourceDatabaseId must be specified as the resource ID of the existing database, and restorePointInTime must be specified. - + Recovery: Creates a database by restoring a geo-replicated backup. sourceDatabaseId must be specified as the recoverable database resource ID to restore. - + Restore: Creates a database by restoring a backup of a deleted database. sourceDatabaseId must be specified. If sourceDatabaseId is the database's original resource ID, then sourceDatabaseDeletionDate must be specified. Otherwise sourceDatabaseId must be the restorable dropped database resource ID and sourceDatabaseDeletionDate is ignored. restorePointInTime may also be specified to restore from an earlier point in time. - + RestoreLongTermRetentionBackup: Creates a database by restoring from a long term retention vault. recoveryServicesRecoveryPointResourceId must be specified as the recovery point resource ID. - + Copy, Secondary, and RestoreLongTermRetentionBackup are not supported for DataWarehouse edition. Known values are: "Default", "Copy", "Secondary", "PointInTimeRestore", "Restore", "Recovery", "RestoreExternalBackup", "RestoreExternalBackupSecondary", - "RestoreLongTermRetentionBackup", "OnlineSecondary". + "RestoreLongTermRetentionBackup", and "OnlineSecondary". :paramtype create_mode: str or ~azure.mgmt.sql.models.CreateMode :keyword collation: The collation of the database. :paramtype collation: str :keyword max_size_bytes: The max size of the database expressed in bytes. - :paramtype max_size_bytes: long + :paramtype max_size_bytes: int :keyword sample_name: The name of the sample schema to apply when creating this database. Known - values are: "AdventureWorksLT", "WideWorldImportersStd", "WideWorldImportersFull". + values are: "AdventureWorksLT", "WideWorldImportersStd", and "WideWorldImportersFull". :paramtype sample_name: str or ~azure.mgmt.sql.models.SampleName :keyword elastic_pool_id: The resource identifier of the elastic pool containing this database. :paramtype elastic_pool_id: str @@ -2737,32 +2643,32 @@ def __init__( database associated with create operation of this database. :paramtype restorable_dropped_database_id: str :keyword catalog_collation: Collation of the metadata catalog. Known values are: - "DATABASE_DEFAULT", "SQL_Latin1_General_CP1_CI_AS". + "DATABASE_DEFAULT" and "SQL_Latin1_General_CP1_CI_AS". :paramtype catalog_collation: str or ~azure.mgmt.sql.models.CatalogCollationType :keyword zone_redundant: Whether or not this database is zone redundant, which means the replicas of this database will be spread across multiple availability zones. :paramtype zone_redundant: bool :keyword license_type: The license type to apply for this database. ``LicenseIncluded`` if you need a license, or ``BasePrice`` if you have a license and are eligible for the Azure Hybrid - Benefit. Known values are: "LicenseIncluded", "BasePrice". + Benefit. Known values are: "LicenseIncluded" and "BasePrice". :paramtype license_type: str or ~azure.mgmt.sql.models.DatabaseLicenseType :keyword read_scale: The state of read-only routing. If enabled, connections that have application intent set to readonly in their connection string may be routed to a readonly secondary replica in the same region. Not applicable to a Hyperscale database within an elastic - pool. Known values are: "Enabled", "Disabled". + pool. Known values are: "Enabled" and "Disabled". :paramtype read_scale: str or ~azure.mgmt.sql.models.DatabaseReadScale :keyword high_availability_replica_count: The number of secondary replicas associated with the database that are used to provide high availability. Not applicable to a Hyperscale database within an elastic pool. :paramtype high_availability_replica_count: int :keyword secondary_type: The secondary type of the database if it is a secondary. Valid values - are Geo and Named. Known values are: "Geo", "Named". + are Geo, Named and Standby. Known values are: "Geo", "Named", and "Standby". :paramtype secondary_type: str or ~azure.mgmt.sql.models.SecondaryType :keyword auto_pause_delay: Time in minutes after which database is automatically paused. A value of -1 means that automatic pause is disabled. :paramtype auto_pause_delay: int :keyword requested_backup_storage_redundancy: The storage account type to be used to store - backups for this database. Known values are: "Geo", "Local", "Zone", "GeoZone". + backups for this database. Known values are: "Geo", "Local", "Zone", and "GeoZone". :paramtype requested_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy :keyword min_capacity: Minimal capacity that database will always have allocated, if not @@ -2778,7 +2684,7 @@ def __init__( :keyword federated_client_id: The Client id used for cross tenant per database CMK scenario. :paramtype federated_client_id: str """ - super(DatabaseUpdate, self).__init__(**kwargs) + super().__init__(**kwargs) self.sku = sku self.identity = identity self.tags = tags @@ -2844,39 +2750,35 @@ class DatabaseUsage(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'display_name': {'readonly': True}, - 'current_value': {'readonly': True}, - 'limit': {'readonly': True}, - 'unit': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "display_name": {"readonly": True}, + "current_value": {"readonly": True}, + "limit": {"readonly": True}, + "unit": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'display_name': {'key': 'properties.displayName', 'type': 'str'}, - 'current_value': {'key': 'properties.currentValue', 'type': 'float'}, - 'limit': {'key': 'properties.limit', 'type': 'float'}, - 'unit': {'key': 'properties.unit', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "display_name": {"key": "properties.displayName", "type": "str"}, + "current_value": {"key": "properties.currentValue", "type": "float"}, + "limit": {"key": "properties.limit", "type": "float"}, + "unit": {"key": "properties.unit", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DatabaseUsage, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.display_name = None self.current_value = None self.limit = None self.unit = None -class DatabaseUsageListResult(msrest.serialization.Model): +class DatabaseUsageListResult(_serialization.Model): """A list of database usage metrics. Variables are only populated by the server, and will be ignored when sending a request. @@ -2888,27 +2790,23 @@ class DatabaseUsageListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[DatabaseUsage]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[DatabaseUsage]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DatabaseUsageListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class DatabaseUserIdentity(msrest.serialization.Model): +class DatabaseUserIdentity(_serialization.Model): """Azure Active Directory identity configuration for a resource. Variables are only populated by the server, and will be ignored when sending a request. @@ -2920,22 +2818,18 @@ class DatabaseUserIdentity(msrest.serialization.Model): """ _validation = { - 'principal_id': {'readonly': True}, - 'client_id': {'readonly': True}, + "principal_id": {"readonly": True}, + "client_id": {"readonly": True}, } _attribute_map = { - 'principal_id': {'key': 'principalId', 'type': 'str'}, - 'client_id': {'key': 'clientId', 'type': 'str'}, + "principal_id": {"key": "principalId", "type": "str"}, + "client_id": {"key": "clientId", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DatabaseUserIdentity, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.principal_id = None self.client_id = None @@ -2969,19 +2863,22 @@ class DatabaseVulnerabilityAssessment(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'storage_container_path': {'key': 'properties.storageContainerPath', 'type': 'str'}, - 'storage_container_sas_key': {'key': 'properties.storageContainerSasKey', 'type': 'str'}, - 'storage_account_access_key': {'key': 'properties.storageAccountAccessKey', 'type': 'str'}, - 'recurring_scans': {'key': 'properties.recurringScans', 'type': 'VulnerabilityAssessmentRecurringScansProperties'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "storage_container_path": {"key": "properties.storageContainerPath", "type": "str"}, + "storage_container_sas_key": {"key": "properties.storageContainerSasKey", "type": "str"}, + "storage_account_access_key": {"key": "properties.storageAccountAccessKey", "type": "str"}, + "recurring_scans": { + "key": "properties.recurringScans", + "type": "VulnerabilityAssessmentRecurringScansProperties", + }, } def __init__( @@ -3010,14 +2907,14 @@ def __init__( :paramtype recurring_scans: ~azure.mgmt.sql.models.VulnerabilityAssessmentRecurringScansProperties """ - super(DatabaseVulnerabilityAssessment, self).__init__(**kwargs) + super().__init__(**kwargs) self.storage_container_path = storage_container_path self.storage_container_sas_key = storage_container_sas_key self.storage_account_access_key = storage_account_access_key self.recurring_scans = recurring_scans -class DatabaseVulnerabilityAssessmentListResult(msrest.serialization.Model): +class DatabaseVulnerabilityAssessmentListResult(_serialization.Model): """A list of the database's vulnerability assessments. Variables are only populated by the server, and will be ignored when sending a request. @@ -3029,22 +2926,18 @@ class DatabaseVulnerabilityAssessmentListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[DatabaseVulnerabilityAssessment]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[DatabaseVulnerabilityAssessment]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DatabaseVulnerabilityAssessmentListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -3066,16 +2959,19 @@ class DatabaseVulnerabilityAssessmentRuleBaseline(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'baseline_results': {'key': 'properties.baselineResults', 'type': '[DatabaseVulnerabilityAssessmentRuleBaselineItem]'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "baseline_results": { + "key": "properties.baselineResults", + "type": "[DatabaseVulnerabilityAssessmentRuleBaselineItem]", + }, } def __init__( @@ -3089,38 +2985,33 @@ def __init__( :paramtype baseline_results: list[~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaselineItem] """ - super(DatabaseVulnerabilityAssessmentRuleBaseline, self).__init__(**kwargs) + super().__init__(**kwargs) self.baseline_results = baseline_results -class DatabaseVulnerabilityAssessmentRuleBaselineItem(msrest.serialization.Model): +class DatabaseVulnerabilityAssessmentRuleBaselineItem(_serialization.Model): """Properties for an Azure SQL Database Vulnerability Assessment rule baseline's result. All required parameters must be populated in order to send to Azure. - :ivar result: Required. The rule baseline result. + :ivar result: The rule baseline result. Required. :vartype result: list[str] """ _validation = { - 'result': {'required': True}, + "result": {"required": True}, } _attribute_map = { - 'result': {'key': 'result', 'type': '[str]'}, + "result": {"key": "result", "type": "[str]"}, } - def __init__( - self, - *, - result: List[str], - **kwargs - ): + def __init__(self, *, result: List[str], **kwargs): """ - :keyword result: Required. The rule baseline result. + :keyword result: The rule baseline result. Required. :paramtype result: list[str] """ - super(DatabaseVulnerabilityAssessmentRuleBaselineItem, self).__init__(**kwargs) + super().__init__(**kwargs) self.result = result @@ -3141,26 +3032,22 @@ class DatabaseVulnerabilityAssessmentScansExport(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'exported_report_location': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "exported_report_location": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'exported_report_location': {'key': 'properties.exportedReportLocation', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "exported_report_location": {"key": "properties.exportedReportLocation", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DatabaseVulnerabilityAssessmentScansExport, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.exported_report_location = None @@ -3179,8 +3066,8 @@ class DataMaskingPolicy(ProxyResource): :vartype location: str :ivar kind: The kind of data masking policy. Metadata, used for Azure portal. :vartype kind: str - :ivar data_masking_state: The state of the data masking policy. Known values are: "Disabled", - "Enabled". + :ivar data_masking_state: The state of the data masking policy. Known values are: "Disabled" + and "Enabled". :vartype data_masking_state: str or ~azure.mgmt.sql.models.DataMaskingState :ivar exempt_principals: The list of the exempt principals. Specifies the semicolon-separated list of database users for which the data masking policy does not apply. The specified users @@ -3194,25 +3081,25 @@ class DataMaskingPolicy(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'location': {'readonly': True}, - 'kind': {'readonly': True}, - 'application_principals': {'readonly': True}, - 'masking_level': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "location": {"readonly": True}, + "kind": {"readonly": True}, + "application_principals": {"readonly": True}, + "masking_level": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'kind': {'key': 'kind', 'type': 'str'}, - 'data_masking_state': {'key': 'properties.dataMaskingState', 'type': 'str'}, - 'exempt_principals': {'key': 'properties.exemptPrincipals', 'type': 'str'}, - 'application_principals': {'key': 'properties.applicationPrincipals', 'type': 'str'}, - 'masking_level': {'key': 'properties.maskingLevel', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "kind": {"key": "kind", "type": "str"}, + "data_masking_state": {"key": "properties.dataMaskingState", "type": "str"}, + "exempt_principals": {"key": "properties.exemptPrincipals", "type": "str"}, + "application_principals": {"key": "properties.applicationPrincipals", "type": "str"}, + "masking_level": {"key": "properties.maskingLevel", "type": "str"}, } def __init__( @@ -3223,15 +3110,15 @@ def __init__( **kwargs ): """ - :keyword data_masking_state: The state of the data masking policy. Known values are: - "Disabled", "Enabled". + :keyword data_masking_state: The state of the data masking policy. Known values are: "Disabled" + and "Enabled". :paramtype data_masking_state: str or ~azure.mgmt.sql.models.DataMaskingState :keyword exempt_principals: The list of the exempt principals. Specifies the semicolon-separated list of database users for which the data masking policy does not apply. The specified users receive data results without masking for all of the database queries. :paramtype exempt_principals: str """ - super(DataMaskingPolicy, self).__init__(**kwargs) + super().__init__(**kwargs) self.location = None self.kind = None self.data_masking_state = data_masking_state @@ -3240,7 +3127,7 @@ def __init__( self.masking_level = None -class DataMaskingRule(ProxyResource): +class DataMaskingRule(ProxyResource): # pylint: disable=too-many-instance-attributes """Represents a database data masking rule. Variables are only populated by the server, and will be ignored when sending a request. @@ -3262,7 +3149,7 @@ class DataMaskingRule(ProxyResource): :ivar rule_state: The rule state. Used to delete a rule. To delete an existing rule, specify the schemaName, tableName, columnName, maskingFunction, and specify ruleState as disabled. However, if the rule doesn't already exist, the rule will be created with ruleState set to - enabled, regardless of the provided value of ruleState. Known values are: "Disabled", + enabled, regardless of the provided value of ruleState. Known values are: "Disabled" and "Enabled". :vartype rule_state: str or ~azure.mgmt.sql.models.DataMaskingRuleState :ivar schema_name: The schema name on which the data masking rule is applied. @@ -3272,7 +3159,7 @@ class DataMaskingRule(ProxyResource): :ivar column_name: The column name on which the data masking rule is applied. :vartype column_name: str :ivar masking_function: The masking function that is used for the data masking rule. Known - values are: "Default", "CCN", "Email", "Number", "SSN", "Text". + values are: "Default", "CCN", "Email", "Number", "SSN", and "Text". :vartype masking_function: str or ~azure.mgmt.sql.models.DataMaskingFunction :ivar number_from: The numberFrom property of the masking rule. Required if maskingFunction is set to Number, otherwise this parameter will be ignored. @@ -3292,32 +3179,32 @@ class DataMaskingRule(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'location': {'readonly': True}, - 'kind': {'readonly': True}, - 'id_properties_id': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "location": {"readonly": True}, + "kind": {"readonly": True}, + "id_properties_id": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'kind': {'key': 'kind', 'type': 'str'}, - 'id_properties_id': {'key': 'properties.id', 'type': 'str'}, - 'alias_name': {'key': 'properties.aliasName', 'type': 'str'}, - 'rule_state': {'key': 'properties.ruleState', 'type': 'str'}, - 'schema_name': {'key': 'properties.schemaName', 'type': 'str'}, - 'table_name': {'key': 'properties.tableName', 'type': 'str'}, - 'column_name': {'key': 'properties.columnName', 'type': 'str'}, - 'masking_function': {'key': 'properties.maskingFunction', 'type': 'str'}, - 'number_from': {'key': 'properties.numberFrom', 'type': 'str'}, - 'number_to': {'key': 'properties.numberTo', 'type': 'str'}, - 'prefix_size': {'key': 'properties.prefixSize', 'type': 'str'}, - 'suffix_size': {'key': 'properties.suffixSize', 'type': 'str'}, - 'replacement_string': {'key': 'properties.replacementString', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "kind": {"key": "kind", "type": "str"}, + "id_properties_id": {"key": "properties.id", "type": "str"}, + "alias_name": {"key": "properties.aliasName", "type": "str"}, + "rule_state": {"key": "properties.ruleState", "type": "str"}, + "schema_name": {"key": "properties.schemaName", "type": "str"}, + "table_name": {"key": "properties.tableName", "type": "str"}, + "column_name": {"key": "properties.columnName", "type": "str"}, + "masking_function": {"key": "properties.maskingFunction", "type": "str"}, + "number_from": {"key": "properties.numberFrom", "type": "str"}, + "number_to": {"key": "properties.numberTo", "type": "str"}, + "prefix_size": {"key": "properties.prefixSize", "type": "str"}, + "suffix_size": {"key": "properties.suffixSize", "type": "str"}, + "replacement_string": {"key": "properties.replacementString", "type": "str"}, } def __init__( @@ -3342,7 +3229,7 @@ def __init__( :keyword rule_state: The rule state. Used to delete a rule. To delete an existing rule, specify the schemaName, tableName, columnName, maskingFunction, and specify ruleState as disabled. However, if the rule doesn't already exist, the rule will be created with ruleState set to - enabled, regardless of the provided value of ruleState. Known values are: "Disabled", + enabled, regardless of the provided value of ruleState. Known values are: "Disabled" and "Enabled". :paramtype rule_state: str or ~azure.mgmt.sql.models.DataMaskingRuleState :keyword schema_name: The schema name on which the data masking rule is applied. @@ -3352,7 +3239,7 @@ def __init__( :keyword column_name: The column name on which the data masking rule is applied. :paramtype column_name: str :keyword masking_function: The masking function that is used for the data masking rule. Known - values are: "Default", "CCN", "Email", "Number", "SSN", "Text". + values are: "Default", "CCN", "Email", "Number", "SSN", and "Text". :paramtype masking_function: str or ~azure.mgmt.sql.models.DataMaskingFunction :keyword number_from: The numberFrom property of the masking rule. Required if maskingFunction is set to Number, otherwise this parameter will be ignored. @@ -3370,7 +3257,7 @@ def __init__( masking the unexposed part of the string. Otherwise, this parameter will be ignored. :paramtype replacement_string: str """ - super(DataMaskingRule, self).__init__(**kwargs) + super().__init__(**kwargs) self.location = None self.kind = None self.id_properties_id = None @@ -3387,7 +3274,7 @@ def __init__( self.replacement_string = replacement_string -class DataMaskingRuleListResult(msrest.serialization.Model): +class DataMaskingRuleListResult(_serialization.Model): """The response to a list data masking rules request. :ivar value: The list of database data masking rules. @@ -3395,20 +3282,15 @@ class DataMaskingRuleListResult(msrest.serialization.Model): """ _attribute_map = { - 'value': {'key': 'value', 'type': '[DataMaskingRule]'}, + "value": {"key": "value", "type": "[DataMaskingRule]"}, } - def __init__( - self, - *, - value: Optional[List["_models.DataMaskingRule"]] = None, - **kwargs - ): + def __init__(self, *, value: Optional[List["_models.DataMaskingRule"]] = None, **kwargs): """ :keyword value: The list of database data masking rules. :paramtype value: list[~azure.mgmt.sql.models.DataMaskingRule] """ - super(DataMaskingRuleListResult, self).__init__(**kwargs) + super().__init__(**kwargs) self.value = value @@ -3428,30 +3310,26 @@ class DataWarehouseUserActivities(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'active_queries_count': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "active_queries_count": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'active_queries_count': {'key': 'properties.activeQueriesCount', 'type': 'int'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "active_queries_count": {"key": "properties.activeQueriesCount", "type": "int"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DataWarehouseUserActivities, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.active_queries_count = None -class DataWarehouseUserActivitiesListResult(msrest.serialization.Model): +class DataWarehouseUserActivitiesListResult(_serialization.Model): """User activities of a data warehouse. Variables are only populated by the server, and will be ignored when sending a request. @@ -3463,22 +3341,18 @@ class DataWarehouseUserActivitiesListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[DataWarehouseUserActivities]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[DataWarehouseUserActivities]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DataWarehouseUserActivitiesListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -3505,39 +3379,35 @@ class DeletedServer(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'version': {'readonly': True}, - 'deletion_time': {'readonly': True}, - 'original_id': {'readonly': True}, - 'fully_qualified_domain_name': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "version": {"readonly": True}, + "deletion_time": {"readonly": True}, + "original_id": {"readonly": True}, + "fully_qualified_domain_name": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'version': {'key': 'properties.version', 'type': 'str'}, - 'deletion_time': {'key': 'properties.deletionTime', 'type': 'iso-8601'}, - 'original_id': {'key': 'properties.originalId', 'type': 'str'}, - 'fully_qualified_domain_name': {'key': 'properties.fullyQualifiedDomainName', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "version": {"key": "properties.version", "type": "str"}, + "deletion_time": {"key": "properties.deletionTime", "type": "iso-8601"}, + "original_id": {"key": "properties.originalId", "type": "str"}, + "fully_qualified_domain_name": {"key": "properties.fullyQualifiedDomainName", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DeletedServer, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.version = None self.deletion_time = None self.original_id = None self.fully_qualified_domain_name = None -class DeletedServerListResult(msrest.serialization.Model): +class DeletedServerListResult(_serialization.Model): """A list of deleted servers. Variables are only populated by the server, and will be ignored when sending a request. @@ -3549,27 +3419,23 @@ class DeletedServerListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[DeletedServer]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[DeletedServer]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DeletedServerListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class DistributedAvailabilityGroup(ProxyResource): +class DistributedAvailabilityGroup(ProxyResource): # pylint: disable=too-many-instance-attributes """Distributed availability group between box and Sql Managed Instance. Variables are only populated by the server, and will be ignored when sending a request. @@ -3589,7 +3455,7 @@ class DistributedAvailabilityGroup(ProxyResource): :ivar secondary_availability_group_name: The secondary availability group name. :vartype secondary_availability_group_name: str :ivar replication_mode: The replication mode of a distributed availability group. Parameter - will be ignored during link creation. Known values are: "Async", "Sync". + will be ignored during link creation. Known values are: "Async" and "Sync". :vartype replication_mode: str or ~azure.mgmt.sql.models.ReplicationMode :ivar distributed_availability_group_id: The distributed availability group id. :vartype distributed_availability_group_id: str @@ -3604,30 +3470,30 @@ class DistributedAvailabilityGroup(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'distributed_availability_group_id': {'readonly': True}, - 'source_replica_id': {'readonly': True}, - 'target_replica_id': {'readonly': True}, - 'link_state': {'readonly': True}, - 'last_hardened_lsn': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "distributed_availability_group_id": {"readonly": True}, + "source_replica_id": {"readonly": True}, + "target_replica_id": {"readonly": True}, + "link_state": {"readonly": True}, + "last_hardened_lsn": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'target_database': {'key': 'properties.targetDatabase', 'type': 'str'}, - 'source_endpoint': {'key': 'properties.sourceEndpoint', 'type': 'str'}, - 'primary_availability_group_name': {'key': 'properties.primaryAvailabilityGroupName', 'type': 'str'}, - 'secondary_availability_group_name': {'key': 'properties.secondaryAvailabilityGroupName', 'type': 'str'}, - 'replication_mode': {'key': 'properties.replicationMode', 'type': 'str'}, - 'distributed_availability_group_id': {'key': 'properties.distributedAvailabilityGroupId', 'type': 'str'}, - 'source_replica_id': {'key': 'properties.sourceReplicaId', 'type': 'str'}, - 'target_replica_id': {'key': 'properties.targetReplicaId', 'type': 'str'}, - 'link_state': {'key': 'properties.linkState', 'type': 'str'}, - 'last_hardened_lsn': {'key': 'properties.lastHardenedLsn', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "target_database": {"key": "properties.targetDatabase", "type": "str"}, + "source_endpoint": {"key": "properties.sourceEndpoint", "type": "str"}, + "primary_availability_group_name": {"key": "properties.primaryAvailabilityGroupName", "type": "str"}, + "secondary_availability_group_name": {"key": "properties.secondaryAvailabilityGroupName", "type": "str"}, + "replication_mode": {"key": "properties.replicationMode", "type": "str"}, + "distributed_availability_group_id": {"key": "properties.distributedAvailabilityGroupId", "type": "str"}, + "source_replica_id": {"key": "properties.sourceReplicaId", "type": "str"}, + "target_replica_id": {"key": "properties.targetReplicaId", "type": "str"}, + "link_state": {"key": "properties.linkState", "type": "str"}, + "last_hardened_lsn": {"key": "properties.lastHardenedLsn", "type": "str"}, } def __init__( @@ -3650,10 +3516,10 @@ def __init__( :keyword secondary_availability_group_name: The secondary availability group name. :paramtype secondary_availability_group_name: str :keyword replication_mode: The replication mode of a distributed availability group. Parameter - will be ignored during link creation. Known values are: "Async", "Sync". + will be ignored during link creation. Known values are: "Async" and "Sync". :paramtype replication_mode: str or ~azure.mgmt.sql.models.ReplicationMode """ - super(DistributedAvailabilityGroup, self).__init__(**kwargs) + super().__init__(**kwargs) self.target_database = target_database self.source_endpoint = source_endpoint self.primary_availability_group_name = primary_availability_group_name @@ -3666,7 +3532,7 @@ def __init__( self.last_hardened_lsn = None -class DistributedAvailabilityGroupsListResult(msrest.serialization.Model): +class DistributedAvailabilityGroupsListResult(_serialization.Model): """A list of distributed availability groups in instance. Variables are only populated by the server, and will be ignored when sending a request. @@ -3678,27 +3544,23 @@ class DistributedAvailabilityGroupsListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[DistributedAvailabilityGroup]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[DistributedAvailabilityGroup]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(DistributedAvailabilityGroupsListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class EditionCapability(msrest.serialization.Model): +class EditionCapability(_serialization.Model): """The edition capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -3717,42 +3579,40 @@ class EditionCapability(msrest.serialization.Model): edition. :vartype supported_storage_capabilities: list[~azure.mgmt.sql.models.StorageCapability] :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'name': {'readonly': True}, - 'supported_service_level_objectives': {'readonly': True}, - 'zone_redundant': {'readonly': True}, - 'read_scale': {'readonly': True}, - 'supported_storage_capabilities': {'readonly': True}, - 'status': {'readonly': True}, + "name": {"readonly": True}, + "supported_service_level_objectives": {"readonly": True}, + "zone_redundant": {"readonly": True}, + "read_scale": {"readonly": True}, + "supported_storage_capabilities": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'supported_service_level_objectives': {'key': 'supportedServiceLevelObjectives', 'type': '[ServiceObjectiveCapability]'}, - 'zone_redundant': {'key': 'zoneRedundant', 'type': 'bool'}, - 'read_scale': {'key': 'readScale', 'type': 'ReadScaleCapability'}, - 'supported_storage_capabilities': {'key': 'supportedStorageCapabilities', 'type': '[StorageCapability]'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "name": {"key": "name", "type": "str"}, + "supported_service_level_objectives": { + "key": "supportedServiceLevelObjectives", + "type": "[ServiceObjectiveCapability]", + }, + "zone_redundant": {"key": "zoneRedundant", "type": "bool"}, + "read_scale": {"key": "readScale", "type": "ReadScaleCapability"}, + "supported_storage_capabilities": {"key": "supportedStorageCapabilities", "type": "[StorageCapability]"}, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(EditionCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.name = None self.supported_service_level_objectives = None self.zone_redundant = None @@ -3762,7 +3622,7 @@ def __init__( self.reason = reason -class ElasticPool(TrackedResource): +class ElasticPool(TrackedResource): # pylint: disable=too-many-instance-attributes """An elastic pool. Variables are only populated by the server, and will be ignored when sending a request. @@ -3775,36 +3635,37 @@ class ElasticPool(TrackedResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar location: Required. Resource location. + :ivar location: Resource location. Required. :vartype location: str - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar sku: The elastic pool SKU. - + The list of SKUs may vary by region and support offer. To determine the SKUs (including the SKU name, tier/edition, family, and capacity) that are available to your subscription in an Azure region, use the ``Capabilities_ListByLocation`` REST API or the following command: - + .. code-block:: azurecli - + az sql elastic-pool list-editions -l -o table `. :vartype sku: ~azure.mgmt.sql.models.Sku :ivar kind: Kind of elastic pool. This is metadata used for the Azure portal experience. :vartype kind: str - :ivar state: The state of the elastic pool. Known values are: "Creating", "Ready", "Disabled". + :ivar state: The state of the elastic pool. Known values are: "Creating", "Ready", and + "Disabled". :vartype state: str or ~azure.mgmt.sql.models.ElasticPoolState :ivar creation_date: The creation date of the elastic pool (ISO8601 format). :vartype creation_date: ~datetime.datetime :ivar max_size_bytes: The storage limit for the database elastic pool in bytes. - :vartype max_size_bytes: long + :vartype max_size_bytes: int :ivar per_database_settings: The per database settings for the elastic pool. :vartype per_database_settings: ~azure.mgmt.sql.models.ElasticPoolPerDatabaseSettings :ivar zone_redundant: Whether or not this elastic pool is zone redundant, which means the replicas of this elastic pool will be spread across multiple availability zones. :vartype zone_redundant: bool :ivar license_type: The license type to apply for this elastic pool. Known values are: - "LicenseIncluded", "BasePrice". + "LicenseIncluded" and "BasePrice". :vartype license_type: str or ~azure.mgmt.sql.models.ElasticPoolLicenseType :ivar maintenance_configuration_id: Maintenance configuration id assigned to the elastic pool. This configuration defines the period when the maintenance updates will will occur. @@ -3815,31 +3676,31 @@ class ElasticPool(TrackedResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'location': {'required': True}, - 'kind': {'readonly': True}, - 'state': {'readonly': True}, - 'creation_date': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "location": {"required": True}, + "kind": {"readonly": True}, + "state": {"readonly": True}, + "creation_date": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'tags': {'key': 'tags', 'type': '{str}'}, - 'sku': {'key': 'sku', 'type': 'Sku'}, - 'kind': {'key': 'kind', 'type': 'str'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'creation_date': {'key': 'properties.creationDate', 'type': 'iso-8601'}, - 'max_size_bytes': {'key': 'properties.maxSizeBytes', 'type': 'long'}, - 'per_database_settings': {'key': 'properties.perDatabaseSettings', 'type': 'ElasticPoolPerDatabaseSettings'}, - 'zone_redundant': {'key': 'properties.zoneRedundant', 'type': 'bool'}, - 'license_type': {'key': 'properties.licenseType', 'type': 'str'}, - 'maintenance_configuration_id': {'key': 'properties.maintenanceConfigurationId', 'type': 'str'}, - 'high_availability_replica_count': {'key': 'properties.highAvailabilityReplicaCount', 'type': 'int'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "tags": {"key": "tags", "type": "{str}"}, + "sku": {"key": "sku", "type": "Sku"}, + "kind": {"key": "kind", "type": "str"}, + "state": {"key": "properties.state", "type": "str"}, + "creation_date": {"key": "properties.creationDate", "type": "iso-8601"}, + "max_size_bytes": {"key": "properties.maxSizeBytes", "type": "int"}, + "per_database_settings": {"key": "properties.perDatabaseSettings", "type": "ElasticPoolPerDatabaseSettings"}, + "zone_redundant": {"key": "properties.zoneRedundant", "type": "bool"}, + "license_type": {"key": "properties.licenseType", "type": "str"}, + "maintenance_configuration_id": {"key": "properties.maintenanceConfigurationId", "type": "str"}, + "high_availability_replica_count": {"key": "properties.highAvailabilityReplicaCount", "type": "int"}, } def __init__( @@ -3857,30 +3718,30 @@ def __init__( **kwargs ): """ - :keyword location: Required. Resource location. + :keyword location: Resource location. Required. :paramtype location: str - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] :keyword sku: The elastic pool SKU. - + The list of SKUs may vary by region and support offer. To determine the SKUs (including the SKU name, tier/edition, family, and capacity) that are available to your subscription in an Azure region, use the ``Capabilities_ListByLocation`` REST API or the following command: - + .. code-block:: azurecli - + az sql elastic-pool list-editions -l -o table `. :paramtype sku: ~azure.mgmt.sql.models.Sku :keyword max_size_bytes: The storage limit for the database elastic pool in bytes. - :paramtype max_size_bytes: long + :paramtype max_size_bytes: int :keyword per_database_settings: The per database settings for the elastic pool. :paramtype per_database_settings: ~azure.mgmt.sql.models.ElasticPoolPerDatabaseSettings :keyword zone_redundant: Whether or not this elastic pool is zone redundant, which means the replicas of this elastic pool will be spread across multiple availability zones. :paramtype zone_redundant: bool :keyword license_type: The license type to apply for this elastic pool. Known values are: - "LicenseIncluded", "BasePrice". + "LicenseIncluded" and "BasePrice". :paramtype license_type: str or ~azure.mgmt.sql.models.ElasticPoolLicenseType :keyword maintenance_configuration_id: Maintenance configuration id assigned to the elastic pool. This configuration defines the period when the maintenance updates will will occur. @@ -3889,7 +3750,7 @@ def __init__( elastic pool that are used to provide high availability. :paramtype high_availability_replica_count: int """ - super(ElasticPool, self).__init__(location=location, tags=tags, **kwargs) + super().__init__(location=location, tags=tags, **kwargs) self.sku = sku self.kind = None self.state = None @@ -3902,7 +3763,7 @@ def __init__( self.high_availability_replica_count = high_availability_replica_count -class ElasticPoolActivity(ProxyResource): +class ElasticPoolActivity(ProxyResource): # pylint: disable=too-many-instance-attributes """Represents the activity on an elastic pool. Variables are only populated by the server, and will be ignored when sending a request. @@ -3939,7 +3800,7 @@ class ElasticPoolActivity(ProxyResource): :vartype requested_elastic_pool_name: str :ivar requested_storage_limit_in_gb: The requested storage limit for the pool in GB if available. - :vartype requested_storage_limit_in_gb: long + :vartype requested_storage_limit_in_gb: int :ivar elastic_pool_name: The name of the elastic pool. :vartype elastic_pool_name: str :ivar server_name: The name of the server the elastic pool is in. @@ -3959,69 +3820,64 @@ class ElasticPoolActivity(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'end_time': {'readonly': True}, - 'error_code': {'readonly': True}, - 'error_message': {'readonly': True}, - 'error_severity': {'readonly': True}, - 'operation': {'readonly': True}, - 'operation_id': {'readonly': True}, - 'percent_complete': {'readonly': True}, - 'requested_database_dtu_max': {'readonly': True}, - 'requested_database_dtu_min': {'readonly': True}, - 'requested_dtu': {'readonly': True}, - 'requested_elastic_pool_name': {'readonly': True}, - 'requested_storage_limit_in_gb': {'readonly': True}, - 'elastic_pool_name': {'readonly': True}, - 'server_name': {'readonly': True}, - 'start_time': {'readonly': True}, - 'state': {'readonly': True}, - 'requested_storage_limit_in_mb': {'readonly': True}, - 'requested_database_dtu_guarantee': {'readonly': True}, - 'requested_database_dtu_cap': {'readonly': True}, - 'requested_dtu_guarantee': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'end_time': {'key': 'properties.endTime', 'type': 'iso-8601'}, - 'error_code': {'key': 'properties.errorCode', 'type': 'int'}, - 'error_message': {'key': 'properties.errorMessage', 'type': 'str'}, - 'error_severity': {'key': 'properties.errorSeverity', 'type': 'int'}, - 'operation': {'key': 'properties.operation', 'type': 'str'}, - 'operation_id': {'key': 'properties.operationId', 'type': 'str'}, - 'percent_complete': {'key': 'properties.percentComplete', 'type': 'int'}, - 'requested_database_dtu_max': {'key': 'properties.requestedDatabaseDtuMax', 'type': 'int'}, - 'requested_database_dtu_min': {'key': 'properties.requestedDatabaseDtuMin', 'type': 'int'}, - 'requested_dtu': {'key': 'properties.requestedDtu', 'type': 'int'}, - 'requested_elastic_pool_name': {'key': 'properties.requestedElasticPoolName', 'type': 'str'}, - 'requested_storage_limit_in_gb': {'key': 'properties.requestedStorageLimitInGB', 'type': 'long'}, - 'elastic_pool_name': {'key': 'properties.elasticPoolName', 'type': 'str'}, - 'server_name': {'key': 'properties.serverName', 'type': 'str'}, - 'start_time': {'key': 'properties.startTime', 'type': 'iso-8601'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'requested_storage_limit_in_mb': {'key': 'properties.requestedStorageLimitInMB', 'type': 'int'}, - 'requested_database_dtu_guarantee': {'key': 'properties.requestedDatabaseDtuGuarantee', 'type': 'int'}, - 'requested_database_dtu_cap': {'key': 'properties.requestedDatabaseDtuCap', 'type': 'int'}, - 'requested_dtu_guarantee': {'key': 'properties.requestedDtuGuarantee', 'type': 'int'}, - } - - def __init__( - self, - *, - location: Optional[str] = None, - **kwargs - ): + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "end_time": {"readonly": True}, + "error_code": {"readonly": True}, + "error_message": {"readonly": True}, + "error_severity": {"readonly": True}, + "operation": {"readonly": True}, + "operation_id": {"readonly": True}, + "percent_complete": {"readonly": True}, + "requested_database_dtu_max": {"readonly": True}, + "requested_database_dtu_min": {"readonly": True}, + "requested_dtu": {"readonly": True}, + "requested_elastic_pool_name": {"readonly": True}, + "requested_storage_limit_in_gb": {"readonly": True}, + "elastic_pool_name": {"readonly": True}, + "server_name": {"readonly": True}, + "start_time": {"readonly": True}, + "state": {"readonly": True}, + "requested_storage_limit_in_mb": {"readonly": True}, + "requested_database_dtu_guarantee": {"readonly": True}, + "requested_database_dtu_cap": {"readonly": True}, + "requested_dtu_guarantee": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "end_time": {"key": "properties.endTime", "type": "iso-8601"}, + "error_code": {"key": "properties.errorCode", "type": "int"}, + "error_message": {"key": "properties.errorMessage", "type": "str"}, + "error_severity": {"key": "properties.errorSeverity", "type": "int"}, + "operation": {"key": "properties.operation", "type": "str"}, + "operation_id": {"key": "properties.operationId", "type": "str"}, + "percent_complete": {"key": "properties.percentComplete", "type": "int"}, + "requested_database_dtu_max": {"key": "properties.requestedDatabaseDtuMax", "type": "int"}, + "requested_database_dtu_min": {"key": "properties.requestedDatabaseDtuMin", "type": "int"}, + "requested_dtu": {"key": "properties.requestedDtu", "type": "int"}, + "requested_elastic_pool_name": {"key": "properties.requestedElasticPoolName", "type": "str"}, + "requested_storage_limit_in_gb": {"key": "properties.requestedStorageLimitInGB", "type": "int"}, + "elastic_pool_name": {"key": "properties.elasticPoolName", "type": "str"}, + "server_name": {"key": "properties.serverName", "type": "str"}, + "start_time": {"key": "properties.startTime", "type": "iso-8601"}, + "state": {"key": "properties.state", "type": "str"}, + "requested_storage_limit_in_mb": {"key": "properties.requestedStorageLimitInMB", "type": "int"}, + "requested_database_dtu_guarantee": {"key": "properties.requestedDatabaseDtuGuarantee", "type": "int"}, + "requested_database_dtu_cap": {"key": "properties.requestedDatabaseDtuCap", "type": "int"}, + "requested_dtu_guarantee": {"key": "properties.requestedDtuGuarantee", "type": "int"}, + } + + def __init__(self, *, location: Optional[str] = None, **kwargs): # pylint: disable=too-many-locals """ :keyword location: The geo-location where the resource lives. :paramtype location: str """ - super(ElasticPoolActivity, self).__init__(**kwargs) + super().__init__(**kwargs) self.location = location self.end_time = None self.error_code = None @@ -4045,38 +3901,33 @@ def __init__( self.requested_dtu_guarantee = None -class ElasticPoolActivityListResult(msrest.serialization.Model): +class ElasticPoolActivityListResult(_serialization.Model): """Represents the response to a list elastic pool activity request. All required parameters must be populated in order to send to Azure. - :ivar value: Required. The list of elastic pool activities. + :ivar value: The list of elastic pool activities. Required. :vartype value: list[~azure.mgmt.sql.models.ElasticPoolActivity] """ _validation = { - 'value': {'required': True}, + "value": {"required": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ElasticPoolActivity]'}, + "value": {"key": "value", "type": "[ElasticPoolActivity]"}, } - def __init__( - self, - *, - value: List["_models.ElasticPoolActivity"], - **kwargs - ): + def __init__(self, *, value: List["_models.ElasticPoolActivity"], **kwargs): """ - :keyword value: Required. The list of elastic pool activities. + :keyword value: The list of elastic pool activities. Required. :paramtype value: list[~azure.mgmt.sql.models.ElasticPoolActivity] """ - super(ElasticPoolActivityListResult, self).__init__(**kwargs) + super().__init__(**kwargs) self.value = value -class ElasticPoolDatabaseActivity(ProxyResource): +class ElasticPoolDatabaseActivity(ProxyResource): # pylint: disable=too-many-instance-attributes """Represents the activity on an elastic pool. Variables are only populated by the server, and will be ignored when sending a request. @@ -4124,59 +3975,54 @@ class ElasticPoolDatabaseActivity(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'database_name': {'readonly': True}, - 'end_time': {'readonly': True}, - 'error_code': {'readonly': True}, - 'error_message': {'readonly': True}, - 'error_severity': {'readonly': True}, - 'operation': {'readonly': True}, - 'operation_id': {'readonly': True}, - 'percent_complete': {'readonly': True}, - 'requested_elastic_pool_name': {'readonly': True}, - 'current_elastic_pool_name': {'readonly': True}, - 'current_service_objective': {'readonly': True}, - 'requested_service_objective': {'readonly': True}, - 'server_name': {'readonly': True}, - 'start_time': {'readonly': True}, - 'state': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'database_name': {'key': 'properties.databaseName', 'type': 'str'}, - 'end_time': {'key': 'properties.endTime', 'type': 'iso-8601'}, - 'error_code': {'key': 'properties.errorCode', 'type': 'int'}, - 'error_message': {'key': 'properties.errorMessage', 'type': 'str'}, - 'error_severity': {'key': 'properties.errorSeverity', 'type': 'int'}, - 'operation': {'key': 'properties.operation', 'type': 'str'}, - 'operation_id': {'key': 'properties.operationId', 'type': 'str'}, - 'percent_complete': {'key': 'properties.percentComplete', 'type': 'int'}, - 'requested_elastic_pool_name': {'key': 'properties.requestedElasticPoolName', 'type': 'str'}, - 'current_elastic_pool_name': {'key': 'properties.currentElasticPoolName', 'type': 'str'}, - 'current_service_objective': {'key': 'properties.currentServiceObjective', 'type': 'str'}, - 'requested_service_objective': {'key': 'properties.requestedServiceObjective', 'type': 'str'}, - 'server_name': {'key': 'properties.serverName', 'type': 'str'}, - 'start_time': {'key': 'properties.startTime', 'type': 'iso-8601'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - } - - def __init__( - self, - *, - location: Optional[str] = None, - **kwargs - ): + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "database_name": {"readonly": True}, + "end_time": {"readonly": True}, + "error_code": {"readonly": True}, + "error_message": {"readonly": True}, + "error_severity": {"readonly": True}, + "operation": {"readonly": True}, + "operation_id": {"readonly": True}, + "percent_complete": {"readonly": True}, + "requested_elastic_pool_name": {"readonly": True}, + "current_elastic_pool_name": {"readonly": True}, + "current_service_objective": {"readonly": True}, + "requested_service_objective": {"readonly": True}, + "server_name": {"readonly": True}, + "start_time": {"readonly": True}, + "state": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "database_name": {"key": "properties.databaseName", "type": "str"}, + "end_time": {"key": "properties.endTime", "type": "iso-8601"}, + "error_code": {"key": "properties.errorCode", "type": "int"}, + "error_message": {"key": "properties.errorMessage", "type": "str"}, + "error_severity": {"key": "properties.errorSeverity", "type": "int"}, + "operation": {"key": "properties.operation", "type": "str"}, + "operation_id": {"key": "properties.operationId", "type": "str"}, + "percent_complete": {"key": "properties.percentComplete", "type": "int"}, + "requested_elastic_pool_name": {"key": "properties.requestedElasticPoolName", "type": "str"}, + "current_elastic_pool_name": {"key": "properties.currentElasticPoolName", "type": "str"}, + "current_service_objective": {"key": "properties.currentServiceObjective", "type": "str"}, + "requested_service_objective": {"key": "properties.requestedServiceObjective", "type": "str"}, + "server_name": {"key": "properties.serverName", "type": "str"}, + "start_time": {"key": "properties.startTime", "type": "iso-8601"}, + "state": {"key": "properties.state", "type": "str"}, + } + + def __init__(self, *, location: Optional[str] = None, **kwargs): """ :keyword location: The geo-location where the resource lives. :paramtype location: str """ - super(ElasticPoolDatabaseActivity, self).__init__(**kwargs) + super().__init__(**kwargs) self.location = location self.database_name = None self.end_time = None @@ -4195,38 +4041,33 @@ def __init__( self.state = None -class ElasticPoolDatabaseActivityListResult(msrest.serialization.Model): +class ElasticPoolDatabaseActivityListResult(_serialization.Model): """Represents the response to a list elastic pool database activity request. All required parameters must be populated in order to send to Azure. - :ivar value: Required. The list of elastic pool database activities. + :ivar value: The list of elastic pool database activities. Required. :vartype value: list[~azure.mgmt.sql.models.ElasticPoolDatabaseActivity] """ _validation = { - 'value': {'required': True}, + "value": {"required": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ElasticPoolDatabaseActivity]'}, + "value": {"key": "value", "type": "[ElasticPoolDatabaseActivity]"}, } - def __init__( - self, - *, - value: List["_models.ElasticPoolDatabaseActivity"], - **kwargs - ): + def __init__(self, *, value: List["_models.ElasticPoolDatabaseActivity"], **kwargs): """ - :keyword value: Required. The list of elastic pool database activities. + :keyword value: The list of elastic pool database activities. Required. :paramtype value: list[~azure.mgmt.sql.models.ElasticPoolDatabaseActivity] """ - super(ElasticPoolDatabaseActivityListResult, self).__init__(**kwargs) + super().__init__(**kwargs) self.value = value -class ElasticPoolEditionCapability(msrest.serialization.Model): +class ElasticPoolEditionCapability(_serialization.Model): """The elastic pool edition capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -4240,38 +4081,36 @@ class ElasticPoolEditionCapability(msrest.serialization.Model): :ivar zone_redundant: Whether or not zone redundancy is supported for the edition. :vartype zone_redundant: bool :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'name': {'readonly': True}, - 'supported_elastic_pool_performance_levels': {'readonly': True}, - 'zone_redundant': {'readonly': True}, - 'status': {'readonly': True}, + "name": {"readonly": True}, + "supported_elastic_pool_performance_levels": {"readonly": True}, + "zone_redundant": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'supported_elastic_pool_performance_levels': {'key': 'supportedElasticPoolPerformanceLevels', 'type': '[ElasticPoolPerformanceLevelCapability]'}, - 'zone_redundant': {'key': 'zoneRedundant', 'type': 'bool'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "name": {"key": "name", "type": "str"}, + "supported_elastic_pool_performance_levels": { + "key": "supportedElasticPoolPerformanceLevels", + "type": "[ElasticPoolPerformanceLevelCapability]", + }, + "zone_redundant": {"key": "zoneRedundant", "type": "bool"}, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(ElasticPoolEditionCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.name = None self.supported_elastic_pool_performance_levels = None self.zone_redundant = None @@ -4279,7 +4118,7 @@ def __init__( self.reason = reason -class ElasticPoolListResult(msrest.serialization.Model): +class ElasticPoolListResult(_serialization.Model): """The result of an elastic pool list request. Variables are only populated by the server, and will be ignored when sending a request. @@ -4291,27 +4130,23 @@ class ElasticPoolListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ElasticPool]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ElasticPool]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ElasticPoolListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ElasticPoolOperation(ProxyResource): +class ElasticPoolOperation(ProxyResource): # pylint: disable=too-many-instance-attributes """A elastic pool operation. Variables are only populated by the server, and will be ignored when sending a request. @@ -4353,52 +4188,48 @@ class ElasticPoolOperation(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'elastic_pool_name': {'readonly': True}, - 'operation': {'readonly': True}, - 'operation_friendly_name': {'readonly': True}, - 'percent_complete': {'readonly': True}, - 'server_name': {'readonly': True}, - 'start_time': {'readonly': True}, - 'state': {'readonly': True}, - 'error_code': {'readonly': True}, - 'error_description': {'readonly': True}, - 'error_severity': {'readonly': True}, - 'is_user_error': {'readonly': True}, - 'estimated_completion_time': {'readonly': True}, - 'description': {'readonly': True}, - 'is_cancellable': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'elastic_pool_name': {'key': 'properties.elasticPoolName', 'type': 'str'}, - 'operation': {'key': 'properties.operation', 'type': 'str'}, - 'operation_friendly_name': {'key': 'properties.operationFriendlyName', 'type': 'str'}, - 'percent_complete': {'key': 'properties.percentComplete', 'type': 'int'}, - 'server_name': {'key': 'properties.serverName', 'type': 'str'}, - 'start_time': {'key': 'properties.startTime', 'type': 'iso-8601'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'error_code': {'key': 'properties.errorCode', 'type': 'int'}, - 'error_description': {'key': 'properties.errorDescription', 'type': 'str'}, - 'error_severity': {'key': 'properties.errorSeverity', 'type': 'int'}, - 'is_user_error': {'key': 'properties.isUserError', 'type': 'bool'}, - 'estimated_completion_time': {'key': 'properties.estimatedCompletionTime', 'type': 'iso-8601'}, - 'description': {'key': 'properties.description', 'type': 'str'}, - 'is_cancellable': {'key': 'properties.isCancellable', 'type': 'bool'}, - } - - def __init__( - self, - **kwargs - ): - """ - """ - super(ElasticPoolOperation, self).__init__(**kwargs) + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "elastic_pool_name": {"readonly": True}, + "operation": {"readonly": True}, + "operation_friendly_name": {"readonly": True}, + "percent_complete": {"readonly": True}, + "server_name": {"readonly": True}, + "start_time": {"readonly": True}, + "state": {"readonly": True}, + "error_code": {"readonly": True}, + "error_description": {"readonly": True}, + "error_severity": {"readonly": True}, + "is_user_error": {"readonly": True}, + "estimated_completion_time": {"readonly": True}, + "description": {"readonly": True}, + "is_cancellable": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "elastic_pool_name": {"key": "properties.elasticPoolName", "type": "str"}, + "operation": {"key": "properties.operation", "type": "str"}, + "operation_friendly_name": {"key": "properties.operationFriendlyName", "type": "str"}, + "percent_complete": {"key": "properties.percentComplete", "type": "int"}, + "server_name": {"key": "properties.serverName", "type": "str"}, + "start_time": {"key": "properties.startTime", "type": "iso-8601"}, + "state": {"key": "properties.state", "type": "str"}, + "error_code": {"key": "properties.errorCode", "type": "int"}, + "error_description": {"key": "properties.errorDescription", "type": "str"}, + "error_severity": {"key": "properties.errorSeverity", "type": "int"}, + "is_user_error": {"key": "properties.isUserError", "type": "bool"}, + "estimated_completion_time": {"key": "properties.estimatedCompletionTime", "type": "iso-8601"}, + "description": {"key": "properties.description", "type": "str"}, + "is_cancellable": {"key": "properties.isCancellable", "type": "bool"}, + } + + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.elastic_pool_name = None self.operation = None self.operation_friendly_name = None @@ -4415,7 +4246,7 @@ def __init__( self.is_cancellable = None -class ElasticPoolOperationListResult(msrest.serialization.Model): +class ElasticPoolOperationListResult(_serialization.Model): """The response to a list elastic pool operations request. Variables are only populated by the server, and will be ignored when sending a request. @@ -4427,72 +4258,66 @@ class ElasticPoolOperationListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ElasticPoolOperation]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ElasticPoolOperation]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ElasticPoolOperationListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ElasticPoolPerDatabaseMaxPerformanceLevelCapability(msrest.serialization.Model): +class ElasticPoolPerDatabaseMaxPerformanceLevelCapability(_serialization.Model): """The max per-database performance level capability. Variables are only populated by the server, and will be ignored when sending a request. :ivar limit: The maximum performance level per database. :vartype limit: float - :ivar unit: Unit type used to measure performance level. Known values are: "DTU", "VCores". + :ivar unit: Unit type used to measure performance level. Known values are: "DTU" and "VCores". :vartype unit: str or ~azure.mgmt.sql.models.PerformanceLevelUnit :ivar supported_per_database_min_performance_levels: The list of supported min database performance levels. :vartype supported_per_database_min_performance_levels: list[~azure.mgmt.sql.models.ElasticPoolPerDatabaseMinPerformanceLevelCapability] :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'limit': {'readonly': True}, - 'unit': {'readonly': True}, - 'supported_per_database_min_performance_levels': {'readonly': True}, - 'status': {'readonly': True}, + "limit": {"readonly": True}, + "unit": {"readonly": True}, + "supported_per_database_min_performance_levels": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'limit': {'key': 'limit', 'type': 'float'}, - 'unit': {'key': 'unit', 'type': 'str'}, - 'supported_per_database_min_performance_levels': {'key': 'supportedPerDatabaseMinPerformanceLevels', 'type': '[ElasticPoolPerDatabaseMinPerformanceLevelCapability]'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "limit": {"key": "limit", "type": "float"}, + "unit": {"key": "unit", "type": "str"}, + "supported_per_database_min_performance_levels": { + "key": "supportedPerDatabaseMinPerformanceLevels", + "type": "[ElasticPoolPerDatabaseMinPerformanceLevelCapability]", + }, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(ElasticPoolPerDatabaseMaxPerformanceLevelCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.limit = None self.unit = None self.supported_per_database_min_performance_levels = None @@ -4500,53 +4325,48 @@ def __init__( self.reason = reason -class ElasticPoolPerDatabaseMinPerformanceLevelCapability(msrest.serialization.Model): +class ElasticPoolPerDatabaseMinPerformanceLevelCapability(_serialization.Model): """The minimum per-database performance level capability. Variables are only populated by the server, and will be ignored when sending a request. :ivar limit: The minimum performance level per database. :vartype limit: float - :ivar unit: Unit type used to measure performance level. Known values are: "DTU", "VCores". + :ivar unit: Unit type used to measure performance level. Known values are: "DTU" and "VCores". :vartype unit: str or ~azure.mgmt.sql.models.PerformanceLevelUnit :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'limit': {'readonly': True}, - 'unit': {'readonly': True}, - 'status': {'readonly': True}, + "limit": {"readonly": True}, + "unit": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'limit': {'key': 'limit', 'type': 'float'}, - 'unit': {'key': 'unit', 'type': 'str'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "limit": {"key": "limit", "type": "float"}, + "unit": {"key": "unit", "type": "str"}, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(ElasticPoolPerDatabaseMinPerformanceLevelCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.limit = None self.unit = None self.status = None self.reason = reason -class ElasticPoolPerDatabaseSettings(msrest.serialization.Model): +class ElasticPoolPerDatabaseSettings(_serialization.Model): """Per database settings of an elastic pool. :ivar min_capacity: The minimum capacity all databases are guaranteed. @@ -4556,29 +4376,23 @@ class ElasticPoolPerDatabaseSettings(msrest.serialization.Model): """ _attribute_map = { - 'min_capacity': {'key': 'minCapacity', 'type': 'float'}, - 'max_capacity': {'key': 'maxCapacity', 'type': 'float'}, + "min_capacity": {"key": "minCapacity", "type": "float"}, + "max_capacity": {"key": "maxCapacity", "type": "float"}, } - def __init__( - self, - *, - min_capacity: Optional[float] = None, - max_capacity: Optional[float] = None, - **kwargs - ): + def __init__(self, *, min_capacity: Optional[float] = None, max_capacity: Optional[float] = None, **kwargs): """ :keyword min_capacity: The minimum capacity all databases are guaranteed. :paramtype min_capacity: float :keyword max_capacity: The maximum capacity any one database can consume. :paramtype max_capacity: float """ - super(ElasticPoolPerDatabaseSettings, self).__init__(**kwargs) + super().__init__(**kwargs) self.min_capacity = min_capacity self.max_capacity = max_capacity -class ElasticPoolPerformanceLevelCapability(msrest.serialization.Model): +class ElasticPoolPerformanceLevelCapability(_serialization.Model): # pylint: disable=too-many-instance-attributes """The Elastic Pool performance level capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -4607,52 +4421,53 @@ class ElasticPoolPerformanceLevelCapability(msrest.serialization.Model): :vartype supported_maintenance_configurations: list[~azure.mgmt.sql.models.MaintenanceConfigurationCapability] :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'performance_level': {'readonly': True}, - 'sku': {'readonly': True}, - 'supported_license_types': {'readonly': True}, - 'max_database_count': {'readonly': True}, - 'included_max_size': {'readonly': True}, - 'supported_max_sizes': {'readonly': True}, - 'supported_per_database_max_sizes': {'readonly': True}, - 'supported_per_database_max_performance_levels': {'readonly': True}, - 'zone_redundant': {'readonly': True}, - 'supported_maintenance_configurations': {'readonly': True}, - 'status': {'readonly': True}, + "performance_level": {"readonly": True}, + "sku": {"readonly": True}, + "supported_license_types": {"readonly": True}, + "max_database_count": {"readonly": True}, + "included_max_size": {"readonly": True}, + "supported_max_sizes": {"readonly": True}, + "supported_per_database_max_sizes": {"readonly": True}, + "supported_per_database_max_performance_levels": {"readonly": True}, + "zone_redundant": {"readonly": True}, + "supported_maintenance_configurations": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'performance_level': {'key': 'performanceLevel', 'type': 'PerformanceLevelCapability'}, - 'sku': {'key': 'sku', 'type': 'Sku'}, - 'supported_license_types': {'key': 'supportedLicenseTypes', 'type': '[LicenseTypeCapability]'}, - 'max_database_count': {'key': 'maxDatabaseCount', 'type': 'int'}, - 'included_max_size': {'key': 'includedMaxSize', 'type': 'MaxSizeCapability'}, - 'supported_max_sizes': {'key': 'supportedMaxSizes', 'type': '[MaxSizeRangeCapability]'}, - 'supported_per_database_max_sizes': {'key': 'supportedPerDatabaseMaxSizes', 'type': '[MaxSizeRangeCapability]'}, - 'supported_per_database_max_performance_levels': {'key': 'supportedPerDatabaseMaxPerformanceLevels', 'type': '[ElasticPoolPerDatabaseMaxPerformanceLevelCapability]'}, - 'zone_redundant': {'key': 'zoneRedundant', 'type': 'bool'}, - 'supported_maintenance_configurations': {'key': 'supportedMaintenanceConfigurations', 'type': '[MaintenanceConfigurationCapability]'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "performance_level": {"key": "performanceLevel", "type": "PerformanceLevelCapability"}, + "sku": {"key": "sku", "type": "Sku"}, + "supported_license_types": {"key": "supportedLicenseTypes", "type": "[LicenseTypeCapability]"}, + "max_database_count": {"key": "maxDatabaseCount", "type": "int"}, + "included_max_size": {"key": "includedMaxSize", "type": "MaxSizeCapability"}, + "supported_max_sizes": {"key": "supportedMaxSizes", "type": "[MaxSizeRangeCapability]"}, + "supported_per_database_max_sizes": {"key": "supportedPerDatabaseMaxSizes", "type": "[MaxSizeRangeCapability]"}, + "supported_per_database_max_performance_levels": { + "key": "supportedPerDatabaseMaxPerformanceLevels", + "type": "[ElasticPoolPerDatabaseMaxPerformanceLevelCapability]", + }, + "zone_redundant": {"key": "zoneRedundant", "type": "bool"}, + "supported_maintenance_configurations": { + "key": "supportedMaintenanceConfigurations", + "type": "[MaintenanceConfigurationCapability]", + }, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(ElasticPoolPerformanceLevelCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.performance_level = None self.sku = None self.supported_license_types = None @@ -4667,22 +4482,22 @@ def __init__( self.reason = reason -class ElasticPoolUpdate(msrest.serialization.Model): +class ElasticPoolUpdate(_serialization.Model): """An elastic pool update. :ivar sku: An ARM Resource SKU. :vartype sku: ~azure.mgmt.sql.models.Sku - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar max_size_bytes: The storage limit for the database elastic pool in bytes. - :vartype max_size_bytes: long + :vartype max_size_bytes: int :ivar per_database_settings: The per database settings for the elastic pool. :vartype per_database_settings: ~azure.mgmt.sql.models.ElasticPoolPerDatabaseSettings :ivar zone_redundant: Whether or not this elastic pool is zone redundant, which means the replicas of this elastic pool will be spread across multiple availability zones. :vartype zone_redundant: bool :ivar license_type: The license type to apply for this elastic pool. Known values are: - "LicenseIncluded", "BasePrice". + "LicenseIncluded" and "BasePrice". :vartype license_type: str or ~azure.mgmt.sql.models.ElasticPoolLicenseType :ivar maintenance_configuration_id: Maintenance configuration id assigned to the elastic pool. This configuration defines the period when the maintenance updates will will occur. @@ -4694,14 +4509,14 @@ class ElasticPoolUpdate(msrest.serialization.Model): """ _attribute_map = { - 'sku': {'key': 'sku', 'type': 'Sku'}, - 'tags': {'key': 'tags', 'type': '{str}'}, - 'max_size_bytes': {'key': 'properties.maxSizeBytes', 'type': 'long'}, - 'per_database_settings': {'key': 'properties.perDatabaseSettings', 'type': 'ElasticPoolPerDatabaseSettings'}, - 'zone_redundant': {'key': 'properties.zoneRedundant', 'type': 'bool'}, - 'license_type': {'key': 'properties.licenseType', 'type': 'str'}, - 'maintenance_configuration_id': {'key': 'properties.maintenanceConfigurationId', 'type': 'str'}, - 'high_availability_replica_count': {'key': 'properties.highAvailabilityReplicaCount', 'type': 'int'}, + "sku": {"key": "sku", "type": "Sku"}, + "tags": {"key": "tags", "type": "{str}"}, + "max_size_bytes": {"key": "properties.maxSizeBytes", "type": "int"}, + "per_database_settings": {"key": "properties.perDatabaseSettings", "type": "ElasticPoolPerDatabaseSettings"}, + "zone_redundant": {"key": "properties.zoneRedundant", "type": "bool"}, + "license_type": {"key": "properties.licenseType", "type": "str"}, + "maintenance_configuration_id": {"key": "properties.maintenanceConfigurationId", "type": "str"}, + "high_availability_replica_count": {"key": "properties.highAvailabilityReplicaCount", "type": "int"}, } def __init__( @@ -4720,17 +4535,17 @@ def __init__( """ :keyword sku: An ARM Resource SKU. :paramtype sku: ~azure.mgmt.sql.models.Sku - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] :keyword max_size_bytes: The storage limit for the database elastic pool in bytes. - :paramtype max_size_bytes: long + :paramtype max_size_bytes: int :keyword per_database_settings: The per database settings for the elastic pool. :paramtype per_database_settings: ~azure.mgmt.sql.models.ElasticPoolPerDatabaseSettings :keyword zone_redundant: Whether or not this elastic pool is zone redundant, which means the replicas of this elastic pool will be spread across multiple availability zones. :paramtype zone_redundant: bool :keyword license_type: The license type to apply for this elastic pool. Known values are: - "LicenseIncluded", "BasePrice". + "LicenseIncluded" and "BasePrice". :paramtype license_type: str or ~azure.mgmt.sql.models.ElasticPoolLicenseType :keyword maintenance_configuration_id: Maintenance configuration id assigned to the elastic pool. This configuration defines the period when the maintenance updates will will occur. @@ -4740,7 +4555,7 @@ def __init__( pools. :paramtype high_availability_replica_count: int """ - super(ElasticPoolUpdate, self).__init__(**kwargs) + super().__init__(**kwargs) self.sku = sku self.tags = tags self.max_size_bytes = max_size_bytes @@ -4751,7 +4566,7 @@ def __init__( self.high_availability_replica_count = high_availability_replica_count -class EncryptionProtector(ProxyResource): +class EncryptionProtector(ProxyResource): # pylint: disable=too-many-instance-attributes """The server encryption protector. Variables are only populated by the server, and will be ignored when sending a request. @@ -4772,7 +4587,7 @@ class EncryptionProtector(ProxyResource): :ivar server_key_name: The name of the server key. :vartype server_key_name: str :ivar server_key_type: The encryption protector type like 'ServiceManaged', 'AzureKeyVault'. - Known values are: "ServiceManaged", "AzureKeyVault". + Known values are: "ServiceManaged" and "AzureKeyVault". :vartype server_key_type: str or ~azure.mgmt.sql.models.ServerKeyType :ivar uri: The URI of the server key. :vartype uri: str @@ -4783,28 +4598,28 @@ class EncryptionProtector(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'kind': {'readonly': True}, - 'location': {'readonly': True}, - 'subregion': {'readonly': True}, - 'uri': {'readonly': True}, - 'thumbprint': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "kind": {"readonly": True}, + "location": {"readonly": True}, + "subregion": {"readonly": True}, + "uri": {"readonly": True}, + "thumbprint": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'kind': {'key': 'kind', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'subregion': {'key': 'properties.subregion', 'type': 'str'}, - 'server_key_name': {'key': 'properties.serverKeyName', 'type': 'str'}, - 'server_key_type': {'key': 'properties.serverKeyType', 'type': 'str'}, - 'uri': {'key': 'properties.uri', 'type': 'str'}, - 'thumbprint': {'key': 'properties.thumbprint', 'type': 'str'}, - 'auto_rotation_enabled': {'key': 'properties.autoRotationEnabled', 'type': 'bool'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "kind": {"key": "kind", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "subregion": {"key": "properties.subregion", "type": "str"}, + "server_key_name": {"key": "properties.serverKeyName", "type": "str"}, + "server_key_type": {"key": "properties.serverKeyType", "type": "str"}, + "uri": {"key": "properties.uri", "type": "str"}, + "thumbprint": {"key": "properties.thumbprint", "type": "str"}, + "auto_rotation_enabled": {"key": "properties.autoRotationEnabled", "type": "bool"}, } def __init__( @@ -4819,12 +4634,12 @@ def __init__( :keyword server_key_name: The name of the server key. :paramtype server_key_name: str :keyword server_key_type: The encryption protector type like 'ServiceManaged', 'AzureKeyVault'. - Known values are: "ServiceManaged", "AzureKeyVault". + Known values are: "ServiceManaged" and "AzureKeyVault". :paramtype server_key_type: str or ~azure.mgmt.sql.models.ServerKeyType :keyword auto_rotation_enabled: Key auto rotation opt-in flag. Either true or false. :paramtype auto_rotation_enabled: bool """ - super(EncryptionProtector, self).__init__(**kwargs) + super().__init__(**kwargs) self.kind = None self.location = None self.subregion = None @@ -4835,7 +4650,7 @@ def __init__( self.auto_rotation_enabled = auto_rotation_enabled -class EncryptionProtectorListResult(msrest.serialization.Model): +class EncryptionProtectorListResult(_serialization.Model): """A list of server encryption protectors. Variables are only populated by the server, and will be ignored when sending a request. @@ -4847,22 +4662,18 @@ class EncryptionProtectorListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[EncryptionProtector]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[EncryptionProtector]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(EncryptionProtectorListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -4883,33 +4694,28 @@ class EndpointCertificate(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'public_blob': {'key': 'properties.publicBlob', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "public_blob": {"key": "properties.publicBlob", "type": "str"}, } - def __init__( - self, - *, - public_blob: Optional[str] = None, - **kwargs - ): + def __init__(self, *, public_blob: Optional[str] = None, **kwargs): """ :keyword public_blob: The certificate public blob. :paramtype public_blob: str """ - super(EndpointCertificate, self).__init__(**kwargs) + super().__init__(**kwargs) self.public_blob = public_blob -class EndpointCertificateListResult(msrest.serialization.Model): +class EndpointCertificateListResult(_serialization.Model): """A list of endpoint certificates on the target instance. Variables are only populated by the server, and will be ignored when sending a request. @@ -4921,41 +4727,37 @@ class EndpointCertificateListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[EndpointCertificate]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[EndpointCertificate]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(EndpointCertificateListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ExportDatabaseDefinition(msrest.serialization.Model): +class ExportDatabaseDefinition(_serialization.Model): """Contains the information necessary to perform export database operation. All required parameters must be populated in order to send to Azure. - :ivar storage_key_type: Required. Storage key type. Known values are: "SharedAccessKey", + :ivar storage_key_type: Storage key type. Required. Known values are: "SharedAccessKey" and "StorageAccessKey". :vartype storage_key_type: str or ~azure.mgmt.sql.models.StorageKeyType - :ivar storage_key: Required. Storage key. + :ivar storage_key: Storage key. Required. :vartype storage_key: str - :ivar storage_uri: Required. Storage Uri. + :ivar storage_uri: Storage Uri. Required. :vartype storage_uri: str - :ivar administrator_login: Required. Administrator login name. + :ivar administrator_login: Administrator login name. Required. :vartype administrator_login: str - :ivar administrator_login_password: Required. Administrator login password. + :ivar administrator_login_password: Administrator login password. Required. :vartype administrator_login_password: str :ivar authentication_type: Authentication type. :vartype authentication_type: str @@ -4964,21 +4766,21 @@ class ExportDatabaseDefinition(msrest.serialization.Model): """ _validation = { - 'storage_key_type': {'required': True}, - 'storage_key': {'required': True}, - 'storage_uri': {'required': True}, - 'administrator_login': {'required': True}, - 'administrator_login_password': {'required': True}, + "storage_key_type": {"required": True}, + "storage_key": {"required": True}, + "storage_uri": {"required": True}, + "administrator_login": {"required": True}, + "administrator_login_password": {"required": True}, } _attribute_map = { - 'storage_key_type': {'key': 'storageKeyType', 'type': 'str'}, - 'storage_key': {'key': 'storageKey', 'type': 'str'}, - 'storage_uri': {'key': 'storageUri', 'type': 'str'}, - 'administrator_login': {'key': 'administratorLogin', 'type': 'str'}, - 'administrator_login_password': {'key': 'administratorLoginPassword', 'type': 'str'}, - 'authentication_type': {'key': 'authenticationType', 'type': 'str'}, - 'network_isolation': {'key': 'networkIsolation', 'type': 'NetworkIsolationSettings'}, + "storage_key_type": {"key": "storageKeyType", "type": "str"}, + "storage_key": {"key": "storageKey", "type": "str"}, + "storage_uri": {"key": "storageUri", "type": "str"}, + "administrator_login": {"key": "administratorLogin", "type": "str"}, + "administrator_login_password": {"key": "administratorLoginPassword", "type": "str"}, + "authentication_type": {"key": "authenticationType", "type": "str"}, + "network_isolation": {"key": "networkIsolation", "type": "NetworkIsolationSettings"}, } def __init__( @@ -4994,16 +4796,16 @@ def __init__( **kwargs ): """ - :keyword storage_key_type: Required. Storage key type. Known values are: "SharedAccessKey", + :keyword storage_key_type: Storage key type. Required. Known values are: "SharedAccessKey" and "StorageAccessKey". :paramtype storage_key_type: str or ~azure.mgmt.sql.models.StorageKeyType - :keyword storage_key: Required. Storage key. + :keyword storage_key: Storage key. Required. :paramtype storage_key: str - :keyword storage_uri: Required. Storage Uri. + :keyword storage_uri: Storage Uri. Required. :paramtype storage_uri: str - :keyword administrator_login: Required. Administrator login name. + :keyword administrator_login: Administrator login name. Required. :paramtype administrator_login: str - :keyword administrator_login_password: Required. Administrator login password. + :keyword administrator_login_password: Administrator login password. Required. :paramtype administrator_login_password: str :keyword authentication_type: Authentication type. :paramtype authentication_type: str @@ -5011,7 +4813,7 @@ def __init__( request. :paramtype network_isolation: ~azure.mgmt.sql.models.NetworkIsolationSettings """ - super(ExportDatabaseDefinition, self).__init__(**kwargs) + super().__init__(**kwargs) self.storage_key_type = storage_key_type self.storage_key = storage_key self.storage_uri = storage_uri @@ -5021,7 +4823,7 @@ def __init__( self.network_isolation = network_isolation -class ExtendedDatabaseBlobAuditingPolicy(ProxyResource): +class ExtendedDatabaseBlobAuditingPolicy(ProxyResource): # pylint: disable=too-many-instance-attributes """An extended database blob auditing policy. Variables are only populated by the server, and will be ignored when sending a request. @@ -5038,21 +4840,21 @@ class ExtendedDatabaseBlobAuditingPolicy(ProxyResource): account. :vartype retention_days: int :ivar audit_actions_and_groups: Specifies the Actions-Groups and Actions to audit. - + The recommended set of action groups to use is the following combination - this will audit all the queries and stored procedures executed against the database, as well as successful and failed logins: - + BATCH_COMPLETED_GROUP, SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP, FAILED_DATABASE_AUTHENTICATION_GROUP. - + This above combination is also the set that is configured by default when enabling auditing from the Azure portal. - + The supported action groups to audit are (note: choose only specific groups that cover your auditing needs. Using unnecessary groups could lead to very large quantities of audit records): - + APPLICATION_ROLE_CHANGE_PASSWORD_GROUP BACKUP_RESTORE_GROUP DATABASE_LOGOUT_GROUP @@ -5077,14 +4879,14 @@ class ExtendedDatabaseBlobAuditingPolicy(ProxyResource): DATABASE_OWNERSHIP_CHANGE_GROUP DATABASE_CHANGE_GROUP LEDGER_OPERATION_GROUP - + These are groups that cover all sql statements and stored procedures executed against the database, and should not be used in combination with other groups as this will result in duplicate audit logs. - + For more information, see `Database-Level Audit Action Groups `_. - + For Database auditing policy, specific Actions can also be specified (note that Actions cannot be specified for Server auditing policy). The supported actions to audit are: SELECT @@ -5094,19 +4896,19 @@ class ExtendedDatabaseBlobAuditingPolicy(ProxyResource): EXECUTE RECEIVE REFERENCES - + The general form for defining an action to be audited is: {action} ON {object} BY {principal} - + Note that :code:`` in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE::{db_name} and SCHEMA::{schema_name} are used, respectively. - + For example: SELECT on dbo.myTable by public SELECT on DATABASE::myDatabase by public SELECT on SCHEMA::mySchema by public - + For more information, see `Database-Level Audit Actions `_. :vartype audit_actions_and_groups: list[str] @@ -5117,15 +4919,15 @@ class ExtendedDatabaseBlobAuditingPolicy(ProxyResource): Monitor. In order to send the events to Azure Monitor, specify 'State' as 'Enabled' and 'IsAzureMonitorTargetEnabled' as true. - + When using REST API to configure auditing, Diagnostic Settings with 'SQLSecurityAuditEvents' diagnostic logs category on the database should be also created. Note that for server level audit you should use the 'master' database as {databaseName}. - + Diagnostic Settings URI format: PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview - + For more information, see `Diagnostic Settings REST API `_ or `Diagnostic Settings PowerShell `_. @@ -5138,7 +4940,7 @@ class ExtendedDatabaseBlobAuditingPolicy(ProxyResource): storage. :vartype is_managed_identity_in_use: bool :ivar state: Specifies the state of the audit. If state is Enabled, storageEndpoint or - isAzureMonitorTargetEnabled are required. Known values are: "Enabled", "Disabled". + isAzureMonitorTargetEnabled are required. Known values are: "Enabled" and "Disabled". :vartype state: str or ~azure.mgmt.sql.models.BlobAuditingPolicyState :ivar storage_endpoint: Specifies the blob storage endpoint (e.g. https://MyAccount.blob.core.windows.net). If state is Enabled, storageEndpoint or @@ -5149,8 +4951,8 @@ class ExtendedDatabaseBlobAuditingPolicy(ProxyResource): storageAccountAccessKey will use SQL server system-assigned managed identity to access the storage. Prerequisites for using managed identity authentication: - - + + #. Assign SQL Server a system-assigned managed identity in Azure Active Directory (AAD). #. Grant SQL Server identity access to the storage account by adding 'Storage Blob Data Contributor' RBAC role to the server identity. @@ -5162,26 +4964,26 @@ class ExtendedDatabaseBlobAuditingPolicy(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'predicate_expression': {'key': 'properties.predicateExpression', 'type': 'str'}, - 'retention_days': {'key': 'properties.retentionDays', 'type': 'int'}, - 'audit_actions_and_groups': {'key': 'properties.auditActionsAndGroups', 'type': '[str]'}, - 'is_storage_secondary_key_in_use': {'key': 'properties.isStorageSecondaryKeyInUse', 'type': 'bool'}, - 'is_azure_monitor_target_enabled': {'key': 'properties.isAzureMonitorTargetEnabled', 'type': 'bool'}, - 'queue_delay_ms': {'key': 'properties.queueDelayMs', 'type': 'int'}, - 'is_managed_identity_in_use': {'key': 'properties.isManagedIdentityInUse', 'type': 'bool'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'storage_endpoint': {'key': 'properties.storageEndpoint', 'type': 'str'}, - 'storage_account_access_key': {'key': 'properties.storageAccountAccessKey', 'type': 'str'}, - 'storage_account_subscription_id': {'key': 'properties.storageAccountSubscriptionId', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "predicate_expression": {"key": "properties.predicateExpression", "type": "str"}, + "retention_days": {"key": "properties.retentionDays", "type": "int"}, + "audit_actions_and_groups": {"key": "properties.auditActionsAndGroups", "type": "[str]"}, + "is_storage_secondary_key_in_use": {"key": "properties.isStorageSecondaryKeyInUse", "type": "bool"}, + "is_azure_monitor_target_enabled": {"key": "properties.isAzureMonitorTargetEnabled", "type": "bool"}, + "queue_delay_ms": {"key": "properties.queueDelayMs", "type": "int"}, + "is_managed_identity_in_use": {"key": "properties.isManagedIdentityInUse", "type": "bool"}, + "state": {"key": "properties.state", "type": "str"}, + "storage_endpoint": {"key": "properties.storageEndpoint", "type": "str"}, + "storage_account_access_key": {"key": "properties.storageAccountAccessKey", "type": "str"}, + "storage_account_subscription_id": {"key": "properties.storageAccountSubscriptionId", "type": "str"}, } def __init__( @@ -5207,21 +5009,21 @@ def __init__( account. :paramtype retention_days: int :keyword audit_actions_and_groups: Specifies the Actions-Groups and Actions to audit. - + The recommended set of action groups to use is the following combination - this will audit all the queries and stored procedures executed against the database, as well as successful and failed logins: - + BATCH_COMPLETED_GROUP, SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP, FAILED_DATABASE_AUTHENTICATION_GROUP. - + This above combination is also the set that is configured by default when enabling auditing from the Azure portal. - + The supported action groups to audit are (note: choose only specific groups that cover your auditing needs. Using unnecessary groups could lead to very large quantities of audit records): - + APPLICATION_ROLE_CHANGE_PASSWORD_GROUP BACKUP_RESTORE_GROUP DATABASE_LOGOUT_GROUP @@ -5246,14 +5048,14 @@ def __init__( DATABASE_OWNERSHIP_CHANGE_GROUP DATABASE_CHANGE_GROUP LEDGER_OPERATION_GROUP - + These are groups that cover all sql statements and stored procedures executed against the database, and should not be used in combination with other groups as this will result in duplicate audit logs. - + For more information, see `Database-Level Audit Action Groups `_. - + For Database auditing policy, specific Actions can also be specified (note that Actions cannot be specified for Server auditing policy). The supported actions to audit are: SELECT @@ -5263,19 +5065,19 @@ def __init__( EXECUTE RECEIVE REFERENCES - + The general form for defining an action to be audited is: {action} ON {object} BY {principal} - + Note that :code:`` in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE::{db_name} and SCHEMA::{schema_name} are used, respectively. - + For example: SELECT on dbo.myTable by public SELECT on DATABASE::myDatabase by public SELECT on SCHEMA::mySchema by public - + For more information, see `Database-Level Audit Actions `_. :paramtype audit_actions_and_groups: list[str] @@ -5286,15 +5088,15 @@ def __init__( Monitor. In order to send the events to Azure Monitor, specify 'State' as 'Enabled' and 'IsAzureMonitorTargetEnabled' as true. - + When using REST API to configure auditing, Diagnostic Settings with 'SQLSecurityAuditEvents' diagnostic logs category on the database should be also created. Note that for server level audit you should use the 'master' database as {databaseName}. - + Diagnostic Settings URI format: PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview - + For more information, see `Diagnostic Settings REST API `_ or `Diagnostic Settings PowerShell `_. @@ -5307,7 +5109,7 @@ def __init__( storage. :paramtype is_managed_identity_in_use: bool :keyword state: Specifies the state of the audit. If state is Enabled, storageEndpoint or - isAzureMonitorTargetEnabled are required. Known values are: "Enabled", "Disabled". + isAzureMonitorTargetEnabled are required. Known values are: "Enabled" and "Disabled". :paramtype state: str or ~azure.mgmt.sql.models.BlobAuditingPolicyState :keyword storage_endpoint: Specifies the blob storage endpoint (e.g. https://MyAccount.blob.core.windows.net). If state is Enabled, storageEndpoint or @@ -5319,8 +5121,8 @@ def __init__( storageAccountAccessKey will use SQL server system-assigned managed identity to access the storage. Prerequisites for using managed identity authentication: - - + + #. Assign SQL Server a system-assigned managed identity in Azure Active Directory (AAD). #. Grant SQL Server identity access to the storage account by adding 'Storage Blob Data Contributor' RBAC role to the server identity. @@ -5330,7 +5132,7 @@ def __init__( :keyword storage_account_subscription_id: Specifies the blob storage subscription Id. :paramtype storage_account_subscription_id: str """ - super(ExtendedDatabaseBlobAuditingPolicy, self).__init__(**kwargs) + super().__init__(**kwargs) self.predicate_expression = predicate_expression self.retention_days = retention_days self.audit_actions_and_groups = audit_actions_and_groups @@ -5344,7 +5146,7 @@ def __init__( self.storage_account_subscription_id = storage_account_subscription_id -class ExtendedDatabaseBlobAuditingPolicyListResult(msrest.serialization.Model): +class ExtendedDatabaseBlobAuditingPolicyListResult(_serialization.Model): """A list of database extended auditing settings. Variables are only populated by the server, and will be ignored when sending a request. @@ -5356,27 +5158,23 @@ class ExtendedDatabaseBlobAuditingPolicyListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ExtendedDatabaseBlobAuditingPolicy]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ExtendedDatabaseBlobAuditingPolicy]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ExtendedDatabaseBlobAuditingPolicyListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ExtendedServerBlobAuditingPolicy(ProxyResource): +class ExtendedServerBlobAuditingPolicy(ProxyResource): # pylint: disable=too-many-instance-attributes """An extended server blob auditing policy. Variables are only populated by the server, and will be ignored when sending a request. @@ -5391,14 +5189,14 @@ class ExtendedServerBlobAuditingPolicy(ProxyResource): logs will be sent to Azure Monitor. In order to send the events to Azure Monitor, specify 'State' as 'Enabled', 'IsAzureMonitorTargetEnabled' as true and 'IsDevopsAuditEnabled' as true - + When using REST API to configure auditing, Diagnostic Settings with 'DevOpsOperationsAudit' diagnostic logs category on the master database should also be created. - + Diagnostic Settings URI format: PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/master/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview - + For more information, see `Diagnostic Settings REST API `_ or `Diagnostic Settings PowerShell `_. @@ -5409,21 +5207,21 @@ class ExtendedServerBlobAuditingPolicy(ProxyResource): account. :vartype retention_days: int :ivar audit_actions_and_groups: Specifies the Actions-Groups and Actions to audit. - + The recommended set of action groups to use is the following combination - this will audit all the queries and stored procedures executed against the database, as well as successful and failed logins: - + BATCH_COMPLETED_GROUP, SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP, FAILED_DATABASE_AUTHENTICATION_GROUP. - + This above combination is also the set that is configured by default when enabling auditing from the Azure portal. - + The supported action groups to audit are (note: choose only specific groups that cover your auditing needs. Using unnecessary groups could lead to very large quantities of audit records): - + APPLICATION_ROLE_CHANGE_PASSWORD_GROUP BACKUP_RESTORE_GROUP DATABASE_LOGOUT_GROUP @@ -5448,14 +5246,14 @@ class ExtendedServerBlobAuditingPolicy(ProxyResource): DATABASE_OWNERSHIP_CHANGE_GROUP DATABASE_CHANGE_GROUP LEDGER_OPERATION_GROUP - + These are groups that cover all sql statements and stored procedures executed against the database, and should not be used in combination with other groups as this will result in duplicate audit logs. - + For more information, see `Database-Level Audit Action Groups `_. - + For Database auditing policy, specific Actions can also be specified (note that Actions cannot be specified for Server auditing policy). The supported actions to audit are: SELECT @@ -5465,19 +5263,19 @@ class ExtendedServerBlobAuditingPolicy(ProxyResource): EXECUTE RECEIVE REFERENCES - + The general form for defining an action to be audited is: {action} ON {object} BY {principal} - + Note that :code:`` in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE::{db_name} and SCHEMA::{schema_name} are used, respectively. - + For example: SELECT on dbo.myTable by public SELECT on DATABASE::myDatabase by public SELECT on SCHEMA::mySchema by public - + For more information, see `Database-Level Audit Actions `_. :vartype audit_actions_and_groups: list[str] @@ -5488,15 +5286,15 @@ class ExtendedServerBlobAuditingPolicy(ProxyResource): Monitor. In order to send the events to Azure Monitor, specify 'State' as 'Enabled' and 'IsAzureMonitorTargetEnabled' as true. - + When using REST API to configure auditing, Diagnostic Settings with 'SQLSecurityAuditEvents' diagnostic logs category on the database should be also created. Note that for server level audit you should use the 'master' database as {databaseName}. - + Diagnostic Settings URI format: PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview - + For more information, see `Diagnostic Settings REST API `_ or `Diagnostic Settings PowerShell `_. @@ -5509,7 +5307,7 @@ class ExtendedServerBlobAuditingPolicy(ProxyResource): storage. :vartype is_managed_identity_in_use: bool :ivar state: Specifies the state of the audit. If state is Enabled, storageEndpoint or - isAzureMonitorTargetEnabled are required. Known values are: "Enabled", "Disabled". + isAzureMonitorTargetEnabled are required. Known values are: "Enabled" and "Disabled". :vartype state: str or ~azure.mgmt.sql.models.BlobAuditingPolicyState :ivar storage_endpoint: Specifies the blob storage endpoint (e.g. https://MyAccount.blob.core.windows.net). If state is Enabled, storageEndpoint or @@ -5520,8 +5318,8 @@ class ExtendedServerBlobAuditingPolicy(ProxyResource): storageAccountAccessKey will use SQL server system-assigned managed identity to access the storage. Prerequisites for using managed identity authentication: - - + + #. Assign SQL Server a system-assigned managed identity in Azure Active Directory (AAD). #. Grant SQL Server identity access to the storage account by adding 'Storage Blob Data Contributor' RBAC role to the server identity. @@ -5533,27 +5331,27 @@ class ExtendedServerBlobAuditingPolicy(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'is_devops_audit_enabled': {'key': 'properties.isDevopsAuditEnabled', 'type': 'bool'}, - 'predicate_expression': {'key': 'properties.predicateExpression', 'type': 'str'}, - 'retention_days': {'key': 'properties.retentionDays', 'type': 'int'}, - 'audit_actions_and_groups': {'key': 'properties.auditActionsAndGroups', 'type': '[str]'}, - 'is_storage_secondary_key_in_use': {'key': 'properties.isStorageSecondaryKeyInUse', 'type': 'bool'}, - 'is_azure_monitor_target_enabled': {'key': 'properties.isAzureMonitorTargetEnabled', 'type': 'bool'}, - 'queue_delay_ms': {'key': 'properties.queueDelayMs', 'type': 'int'}, - 'is_managed_identity_in_use': {'key': 'properties.isManagedIdentityInUse', 'type': 'bool'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'storage_endpoint': {'key': 'properties.storageEndpoint', 'type': 'str'}, - 'storage_account_access_key': {'key': 'properties.storageAccountAccessKey', 'type': 'str'}, - 'storage_account_subscription_id': {'key': 'properties.storageAccountSubscriptionId', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "is_devops_audit_enabled": {"key": "properties.isDevopsAuditEnabled", "type": "bool"}, + "predicate_expression": {"key": "properties.predicateExpression", "type": "str"}, + "retention_days": {"key": "properties.retentionDays", "type": "int"}, + "audit_actions_and_groups": {"key": "properties.auditActionsAndGroups", "type": "[str]"}, + "is_storage_secondary_key_in_use": {"key": "properties.isStorageSecondaryKeyInUse", "type": "bool"}, + "is_azure_monitor_target_enabled": {"key": "properties.isAzureMonitorTargetEnabled", "type": "bool"}, + "queue_delay_ms": {"key": "properties.queueDelayMs", "type": "int"}, + "is_managed_identity_in_use": {"key": "properties.isManagedIdentityInUse", "type": "bool"}, + "state": {"key": "properties.state", "type": "str"}, + "storage_endpoint": {"key": "properties.storageEndpoint", "type": "str"}, + "storage_account_access_key": {"key": "properties.storageAccountAccessKey", "type": "str"}, + "storage_account_subscription_id": {"key": "properties.storageAccountSubscriptionId", "type": "str"}, } def __init__( @@ -5578,14 +5376,14 @@ def __init__( devops logs will be sent to Azure Monitor. In order to send the events to Azure Monitor, specify 'State' as 'Enabled', 'IsAzureMonitorTargetEnabled' as true and 'IsDevopsAuditEnabled' as true - + When using REST API to configure auditing, Diagnostic Settings with 'DevOpsOperationsAudit' diagnostic logs category on the master database should also be created. - + Diagnostic Settings URI format: PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/master/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview - + For more information, see `Diagnostic Settings REST API `_ or `Diagnostic Settings PowerShell `_. @@ -5596,21 +5394,21 @@ def __init__( account. :paramtype retention_days: int :keyword audit_actions_and_groups: Specifies the Actions-Groups and Actions to audit. - + The recommended set of action groups to use is the following combination - this will audit all the queries and stored procedures executed against the database, as well as successful and failed logins: - + BATCH_COMPLETED_GROUP, SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP, FAILED_DATABASE_AUTHENTICATION_GROUP. - + This above combination is also the set that is configured by default when enabling auditing from the Azure portal. - + The supported action groups to audit are (note: choose only specific groups that cover your auditing needs. Using unnecessary groups could lead to very large quantities of audit records): - + APPLICATION_ROLE_CHANGE_PASSWORD_GROUP BACKUP_RESTORE_GROUP DATABASE_LOGOUT_GROUP @@ -5635,14 +5433,14 @@ def __init__( DATABASE_OWNERSHIP_CHANGE_GROUP DATABASE_CHANGE_GROUP LEDGER_OPERATION_GROUP - + These are groups that cover all sql statements and stored procedures executed against the database, and should not be used in combination with other groups as this will result in duplicate audit logs. - + For more information, see `Database-Level Audit Action Groups `_. - + For Database auditing policy, specific Actions can also be specified (note that Actions cannot be specified for Server auditing policy). The supported actions to audit are: SELECT @@ -5652,19 +5450,19 @@ def __init__( EXECUTE RECEIVE REFERENCES - + The general form for defining an action to be audited is: {action} ON {object} BY {principal} - + Note that :code:`` in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE::{db_name} and SCHEMA::{schema_name} are used, respectively. - + For example: SELECT on dbo.myTable by public SELECT on DATABASE::myDatabase by public SELECT on SCHEMA::mySchema by public - + For more information, see `Database-Level Audit Actions `_. :paramtype audit_actions_and_groups: list[str] @@ -5675,15 +5473,15 @@ def __init__( Monitor. In order to send the events to Azure Monitor, specify 'State' as 'Enabled' and 'IsAzureMonitorTargetEnabled' as true. - + When using REST API to configure auditing, Diagnostic Settings with 'SQLSecurityAuditEvents' diagnostic logs category on the database should be also created. Note that for server level audit you should use the 'master' database as {databaseName}. - + Diagnostic Settings URI format: PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview - + For more information, see `Diagnostic Settings REST API `_ or `Diagnostic Settings PowerShell `_. @@ -5696,7 +5494,7 @@ def __init__( storage. :paramtype is_managed_identity_in_use: bool :keyword state: Specifies the state of the audit. If state is Enabled, storageEndpoint or - isAzureMonitorTargetEnabled are required. Known values are: "Enabled", "Disabled". + isAzureMonitorTargetEnabled are required. Known values are: "Enabled" and "Disabled". :paramtype state: str or ~azure.mgmt.sql.models.BlobAuditingPolicyState :keyword storage_endpoint: Specifies the blob storage endpoint (e.g. https://MyAccount.blob.core.windows.net). If state is Enabled, storageEndpoint or @@ -5708,8 +5506,8 @@ def __init__( storageAccountAccessKey will use SQL server system-assigned managed identity to access the storage. Prerequisites for using managed identity authentication: - - + + #. Assign SQL Server a system-assigned managed identity in Azure Active Directory (AAD). #. Grant SQL Server identity access to the storage account by adding 'Storage Blob Data Contributor' RBAC role to the server identity. @@ -5719,7 +5517,7 @@ def __init__( :keyword storage_account_subscription_id: Specifies the blob storage subscription Id. :paramtype storage_account_subscription_id: str """ - super(ExtendedServerBlobAuditingPolicy, self).__init__(**kwargs) + super().__init__(**kwargs) self.is_devops_audit_enabled = is_devops_audit_enabled self.predicate_expression = predicate_expression self.retention_days = retention_days @@ -5734,7 +5532,7 @@ def __init__( self.storage_account_subscription_id = storage_account_subscription_id -class ExtendedServerBlobAuditingPolicyListResult(msrest.serialization.Model): +class ExtendedServerBlobAuditingPolicyListResult(_serialization.Model): """A list of server extended auditing settings. Variables are only populated by the server, and will be ignored when sending a request. @@ -5746,27 +5544,23 @@ class ExtendedServerBlobAuditingPolicyListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ExtendedServerBlobAuditingPolicy]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ExtendedServerBlobAuditingPolicy]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ExtendedServerBlobAuditingPolicyListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class FailoverGroup(ProxyResource): +class FailoverGroup(ProxyResource): # pylint: disable=too-many-instance-attributes """A failover group. Variables are only populated by the server, and will be ignored when sending a request. @@ -5779,14 +5573,14 @@ class FailoverGroup(ProxyResource): :vartype type: str :ivar location: Resource location. :vartype location: str - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar read_write_endpoint: Read-write endpoint of the failover group instance. :vartype read_write_endpoint: ~azure.mgmt.sql.models.FailoverGroupReadWriteEndpoint :ivar read_only_endpoint: Read-only endpoint of the failover group instance. :vartype read_only_endpoint: ~azure.mgmt.sql.models.FailoverGroupReadOnlyEndpoint :ivar replication_role: Local replication role of the failover group instance. Known values - are: "Primary", "Secondary". + are: "Primary" and "Secondary". :vartype replication_role: str or ~azure.mgmt.sql.models.FailoverGroupReplicationRole :ivar replication_state: Replication state of the failover group instance. :vartype replication_state: str @@ -5797,26 +5591,26 @@ class FailoverGroup(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'location': {'readonly': True}, - 'replication_role': {'readonly': True}, - 'replication_state': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "location": {"readonly": True}, + "replication_role": {"readonly": True}, + "replication_state": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'tags': {'key': 'tags', 'type': '{str}'}, - 'read_write_endpoint': {'key': 'properties.readWriteEndpoint', 'type': 'FailoverGroupReadWriteEndpoint'}, - 'read_only_endpoint': {'key': 'properties.readOnlyEndpoint', 'type': 'FailoverGroupReadOnlyEndpoint'}, - 'replication_role': {'key': 'properties.replicationRole', 'type': 'str'}, - 'replication_state': {'key': 'properties.replicationState', 'type': 'str'}, - 'partner_servers': {'key': 'properties.partnerServers', 'type': '[PartnerInfo]'}, - 'databases': {'key': 'properties.databases', 'type': '[str]'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "tags": {"key": "tags", "type": "{str}"}, + "read_write_endpoint": {"key": "properties.readWriteEndpoint", "type": "FailoverGroupReadWriteEndpoint"}, + "read_only_endpoint": {"key": "properties.readOnlyEndpoint", "type": "FailoverGroupReadOnlyEndpoint"}, + "replication_role": {"key": "properties.replicationRole", "type": "str"}, + "replication_state": {"key": "properties.replicationState", "type": "str"}, + "partner_servers": {"key": "properties.partnerServers", "type": "[PartnerInfo]"}, + "databases": {"key": "properties.databases", "type": "[str]"}, } def __init__( @@ -5830,7 +5624,7 @@ def __init__( **kwargs ): """ - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] :keyword read_write_endpoint: Read-write endpoint of the failover group instance. :paramtype read_write_endpoint: ~azure.mgmt.sql.models.FailoverGroupReadWriteEndpoint @@ -5841,7 +5635,7 @@ def __init__( :keyword databases: List of databases in the failover group. :paramtype databases: list[str] """ - super(FailoverGroup, self).__init__(**kwargs) + super().__init__(**kwargs) self.location = None self.tags = tags self.read_write_endpoint = read_write_endpoint @@ -5852,7 +5646,7 @@ def __init__( self.databases = databases -class FailoverGroupListResult(msrest.serialization.Model): +class FailoverGroupListResult(_serialization.Model): """A list of failover groups. Variables are only populated by the server, and will be ignored when sending a request. @@ -5864,61 +5658,54 @@ class FailoverGroupListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[FailoverGroup]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[FailoverGroup]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(FailoverGroupListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class FailoverGroupReadOnlyEndpoint(msrest.serialization.Model): +class FailoverGroupReadOnlyEndpoint(_serialization.Model): """Read-only endpoint of the failover group instance. :ivar failover_policy: Failover policy of the read-only endpoint for the failover group. Known - values are: "Disabled", "Enabled". + values are: "Disabled" and "Enabled". :vartype failover_policy: str or ~azure.mgmt.sql.models.ReadOnlyEndpointFailoverPolicy """ _attribute_map = { - 'failover_policy': {'key': 'failoverPolicy', 'type': 'str'}, + "failover_policy": {"key": "failoverPolicy", "type": "str"}, } def __init__( - self, - *, - failover_policy: Optional[Union[str, "_models.ReadOnlyEndpointFailoverPolicy"]] = None, - **kwargs + self, *, failover_policy: Optional[Union[str, "_models.ReadOnlyEndpointFailoverPolicy"]] = None, **kwargs ): """ :keyword failover_policy: Failover policy of the read-only endpoint for the failover group. - Known values are: "Disabled", "Enabled". + Known values are: "Disabled" and "Enabled". :paramtype failover_policy: str or ~azure.mgmt.sql.models.ReadOnlyEndpointFailoverPolicy """ - super(FailoverGroupReadOnlyEndpoint, self).__init__(**kwargs) + super().__init__(**kwargs) self.failover_policy = failover_policy -class FailoverGroupReadWriteEndpoint(msrest.serialization.Model): +class FailoverGroupReadWriteEndpoint(_serialization.Model): """Read-write endpoint of the failover group instance. All required parameters must be populated in order to send to Azure. - :ivar failover_policy: Required. Failover policy of the read-write endpoint for the failover - group. If failoverPolicy is Automatic then failoverWithDataLossGracePeriodMinutes is required. - Known values are: "Manual", "Automatic". + :ivar failover_policy: Failover policy of the read-write endpoint for the failover group. If + failoverPolicy is Automatic then failoverWithDataLossGracePeriodMinutes is required. Required. + Known values are: "Manual" and "Automatic". :vartype failover_policy: str or ~azure.mgmt.sql.models.ReadWriteEndpointFailoverPolicy :ivar failover_with_data_loss_grace_period_minutes: Grace period before failover with data loss is attempted for the read-write endpoint. If failoverPolicy is Automatic then @@ -5927,12 +5714,15 @@ class FailoverGroupReadWriteEndpoint(msrest.serialization.Model): """ _validation = { - 'failover_policy': {'required': True}, + "failover_policy": {"required": True}, } _attribute_map = { - 'failover_policy': {'key': 'failoverPolicy', 'type': 'str'}, - 'failover_with_data_loss_grace_period_minutes': {'key': 'failoverWithDataLossGracePeriodMinutes', 'type': 'int'}, + "failover_policy": {"key": "failoverPolicy", "type": "str"}, + "failover_with_data_loss_grace_period_minutes": { + "key": "failoverWithDataLossGracePeriodMinutes", + "type": "int", + }, } def __init__( @@ -5943,24 +5733,24 @@ def __init__( **kwargs ): """ - :keyword failover_policy: Required. Failover policy of the read-write endpoint for the failover - group. If failoverPolicy is Automatic then failoverWithDataLossGracePeriodMinutes is required. - Known values are: "Manual", "Automatic". + :keyword failover_policy: Failover policy of the read-write endpoint for the failover group. If + failoverPolicy is Automatic then failoverWithDataLossGracePeriodMinutes is required. Required. + Known values are: "Manual" and "Automatic". :paramtype failover_policy: str or ~azure.mgmt.sql.models.ReadWriteEndpointFailoverPolicy :keyword failover_with_data_loss_grace_period_minutes: Grace period before failover with data loss is attempted for the read-write endpoint. If failoverPolicy is Automatic then failoverWithDataLossGracePeriodMinutes is required. :paramtype failover_with_data_loss_grace_period_minutes: int """ - super(FailoverGroupReadWriteEndpoint, self).__init__(**kwargs) + super().__init__(**kwargs) self.failover_policy = failover_policy self.failover_with_data_loss_grace_period_minutes = failover_with_data_loss_grace_period_minutes -class FailoverGroupUpdate(msrest.serialization.Model): +class FailoverGroupUpdate(_serialization.Model): """A failover group update request. - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar read_write_endpoint: Read-write endpoint of the failover group instance. :vartype read_write_endpoint: ~azure.mgmt.sql.models.FailoverGroupReadWriteEndpoint @@ -5971,10 +5761,10 @@ class FailoverGroupUpdate(msrest.serialization.Model): """ _attribute_map = { - 'tags': {'key': 'tags', 'type': '{str}'}, - 'read_write_endpoint': {'key': 'properties.readWriteEndpoint', 'type': 'FailoverGroupReadWriteEndpoint'}, - 'read_only_endpoint': {'key': 'properties.readOnlyEndpoint', 'type': 'FailoverGroupReadOnlyEndpoint'}, - 'databases': {'key': 'properties.databases', 'type': '[str]'}, + "tags": {"key": "tags", "type": "{str}"}, + "read_write_endpoint": {"key": "properties.readWriteEndpoint", "type": "FailoverGroupReadWriteEndpoint"}, + "read_only_endpoint": {"key": "properties.readOnlyEndpoint", "type": "FailoverGroupReadOnlyEndpoint"}, + "databases": {"key": "properties.databases", "type": "[str]"}, } def __init__( @@ -5987,7 +5777,7 @@ def __init__( **kwargs ): """ - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] :keyword read_write_endpoint: Read-write endpoint of the failover group instance. :paramtype read_write_endpoint: ~azure.mgmt.sql.models.FailoverGroupReadWriteEndpoint @@ -5996,14 +5786,14 @@ def __init__( :keyword databases: List of databases in the failover group. :paramtype databases: list[str] """ - super(FailoverGroupUpdate, self).__init__(**kwargs) + super().__init__(**kwargs) self.tags = tags self.read_write_endpoint = read_write_endpoint self.read_only_endpoint = read_only_endpoint self.databases = databases -class ResourceWithWritableName(msrest.serialization.Model): +class ResourceWithWritableName(_serialization.Model): """ARM resource. Variables are only populated by the server, and will be ignored when sending a request. @@ -6017,27 +5807,22 @@ class ResourceWithWritableName(msrest.serialization.Model): """ _validation = { - 'id': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, } - def __init__( - self, - *, - name: Optional[str] = None, - **kwargs - ): + def __init__(self, *, name: Optional[str] = None, **kwargs): """ :keyword name: Resource name. :paramtype name: str """ - super(ResourceWithWritableName, self).__init__(**kwargs) + super().__init__(**kwargs) self.id = None self.name = name self.type = None @@ -6057,27 +5842,22 @@ class ProxyResourceWithWritableName(ResourceWithWritableName): """ _validation = { - 'id': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, } - def __init__( - self, - *, - name: Optional[str] = None, - **kwargs - ): + def __init__(self, *, name: Optional[str] = None, **kwargs): """ :keyword name: Resource name. :paramtype name: str """ - super(ProxyResourceWithWritableName, self).__init__(name=name, **kwargs) + super().__init__(name=name, **kwargs) class FirewallRule(ProxyResourceWithWritableName): @@ -6101,16 +5881,16 @@ class FirewallRule(ProxyResourceWithWritableName): """ _validation = { - 'id': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'start_ip_address': {'key': 'properties.startIpAddress', 'type': 'str'}, - 'end_ip_address': {'key': 'properties.endIpAddress', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "start_ip_address": {"key": "properties.startIpAddress", "type": "str"}, + "end_ip_address": {"key": "properties.endIpAddress", "type": "str"}, } def __init__( @@ -6132,12 +5912,12 @@ def __init__( addresses. :paramtype end_ip_address: str """ - super(FirewallRule, self).__init__(name=name, **kwargs) + super().__init__(name=name, **kwargs) self.start_ip_address = start_ip_address self.end_ip_address = end_ip_address -class FirewallRuleList(msrest.serialization.Model): +class FirewallRuleList(_serialization.Model): """A list of server firewall rules. :ivar values: @@ -6145,24 +5925,19 @@ class FirewallRuleList(msrest.serialization.Model): """ _attribute_map = { - 'values': {'key': 'values', 'type': '[FirewallRule]'}, + "values": {"key": "values", "type": "[FirewallRule]"}, } - def __init__( - self, - *, - values: Optional[List["_models.FirewallRule"]] = None, - **kwargs - ): + def __init__(self, *, values: Optional[List["_models.FirewallRule"]] = None, **kwargs): """ :keyword values: :paramtype values: list[~azure.mgmt.sql.models.FirewallRule] """ - super(FirewallRuleList, self).__init__(**kwargs) + super().__init__(**kwargs) self.values = values -class FirewallRuleListResult(msrest.serialization.Model): +class FirewallRuleListResult(_serialization.Model): """The response to a list firewall rules request. Variables are only populated by the server, and will be ignored when sending a request. @@ -6174,22 +5949,18 @@ class FirewallRuleListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[FirewallRule]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[FirewallRule]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(FirewallRuleListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -6211,7 +5982,7 @@ class GeoBackupPolicy(ProxyResource): :vartype kind: str :ivar location: Backup policy location. :vartype location: str - :ivar state: Required. The state of the geo backup policy. Known values are: "Disabled", + :ivar state: The state of the geo backup policy. Required. Known values are: "Disabled" and "Enabled". :vartype state: str or ~azure.mgmt.sql.models.GeoBackupPolicyState :ivar storage_type: The storage type of the geo backup policy. @@ -6219,44 +5990,39 @@ class GeoBackupPolicy(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'kind': {'readonly': True}, - 'location': {'readonly': True}, - 'state': {'required': True}, - 'storage_type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "kind": {"readonly": True}, + "location": {"readonly": True}, + "state": {"required": True}, + "storage_type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'kind': {'key': 'kind', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'storage_type': {'key': 'properties.storageType', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "kind": {"key": "kind", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "state": {"key": "properties.state", "type": "str"}, + "storage_type": {"key": "properties.storageType", "type": "str"}, } - def __init__( - self, - *, - state: Union[str, "_models.GeoBackupPolicyState"], - **kwargs - ): + def __init__(self, *, state: Union[str, "_models.GeoBackupPolicyState"], **kwargs): """ - :keyword state: Required. The state of the geo backup policy. Known values are: "Disabled", + :keyword state: The state of the geo backup policy. Required. Known values are: "Disabled" and "Enabled". :paramtype state: str or ~azure.mgmt.sql.models.GeoBackupPolicyState """ - super(GeoBackupPolicy, self).__init__(**kwargs) + super().__init__(**kwargs) self.kind = None self.location = None self.state = state self.storage_type = None -class GeoBackupPolicyListResult(msrest.serialization.Model): +class GeoBackupPolicyListResult(_serialization.Model): """The response to a list geo backup policies request. :ivar value: The list of geo backup policies. @@ -6264,38 +6030,33 @@ class GeoBackupPolicyListResult(msrest.serialization.Model): """ _attribute_map = { - 'value': {'key': 'value', 'type': '[GeoBackupPolicy]'}, + "value": {"key": "value", "type": "[GeoBackupPolicy]"}, } - def __init__( - self, - *, - value: Optional[List["_models.GeoBackupPolicy"]] = None, - **kwargs - ): + def __init__(self, *, value: Optional[List["_models.GeoBackupPolicy"]] = None, **kwargs): """ :keyword value: The list of geo backup policies. :paramtype value: list[~azure.mgmt.sql.models.GeoBackupPolicy] """ - super(GeoBackupPolicyListResult, self).__init__(**kwargs) + super().__init__(**kwargs) self.value = value -class ImportExistingDatabaseDefinition(msrest.serialization.Model): +class ImportExistingDatabaseDefinition(_serialization.Model): """Contains the information necessary to perform import operation for existing database. All required parameters must be populated in order to send to Azure. - :ivar storage_key_type: Required. Storage key type. Known values are: "SharedAccessKey", + :ivar storage_key_type: Storage key type. Required. Known values are: "SharedAccessKey" and "StorageAccessKey". :vartype storage_key_type: str or ~azure.mgmt.sql.models.StorageKeyType - :ivar storage_key: Required. Storage key. + :ivar storage_key: Storage key. Required. :vartype storage_key: str - :ivar storage_uri: Required. Storage Uri. + :ivar storage_uri: Storage Uri. Required. :vartype storage_uri: str - :ivar administrator_login: Required. Administrator login name. + :ivar administrator_login: Administrator login name. Required. :vartype administrator_login: str - :ivar administrator_login_password: Required. Administrator login password. + :ivar administrator_login_password: Administrator login password. Required. :vartype administrator_login_password: str :ivar authentication_type: Authentication type. :vartype authentication_type: str @@ -6304,21 +6065,21 @@ class ImportExistingDatabaseDefinition(msrest.serialization.Model): """ _validation = { - 'storage_key_type': {'required': True}, - 'storage_key': {'required': True}, - 'storage_uri': {'required': True}, - 'administrator_login': {'required': True}, - 'administrator_login_password': {'required': True}, + "storage_key_type": {"required": True}, + "storage_key": {"required": True}, + "storage_uri": {"required": True}, + "administrator_login": {"required": True}, + "administrator_login_password": {"required": True}, } _attribute_map = { - 'storage_key_type': {'key': 'storageKeyType', 'type': 'str'}, - 'storage_key': {'key': 'storageKey', 'type': 'str'}, - 'storage_uri': {'key': 'storageUri', 'type': 'str'}, - 'administrator_login': {'key': 'administratorLogin', 'type': 'str'}, - 'administrator_login_password': {'key': 'administratorLoginPassword', 'type': 'str'}, - 'authentication_type': {'key': 'authenticationType', 'type': 'str'}, - 'network_isolation': {'key': 'networkIsolation', 'type': 'NetworkIsolationSettings'}, + "storage_key_type": {"key": "storageKeyType", "type": "str"}, + "storage_key": {"key": "storageKey", "type": "str"}, + "storage_uri": {"key": "storageUri", "type": "str"}, + "administrator_login": {"key": "administratorLogin", "type": "str"}, + "administrator_login_password": {"key": "administratorLoginPassword", "type": "str"}, + "authentication_type": {"key": "authenticationType", "type": "str"}, + "network_isolation": {"key": "networkIsolation", "type": "NetworkIsolationSettings"}, } def __init__( @@ -6334,16 +6095,16 @@ def __init__( **kwargs ): """ - :keyword storage_key_type: Required. Storage key type. Known values are: "SharedAccessKey", + :keyword storage_key_type: Storage key type. Required. Known values are: "SharedAccessKey" and "StorageAccessKey". :paramtype storage_key_type: str or ~azure.mgmt.sql.models.StorageKeyType - :keyword storage_key: Required. Storage key. + :keyword storage_key: Storage key. Required. :paramtype storage_key: str - :keyword storage_uri: Required. Storage Uri. + :keyword storage_uri: Storage Uri. Required. :paramtype storage_uri: str - :keyword administrator_login: Required. Administrator login name. + :keyword administrator_login: Administrator login name. Required. :paramtype administrator_login: str - :keyword administrator_login_password: Required. Administrator login password. + :keyword administrator_login_password: Administrator login password. Required. :paramtype administrator_login_password: str :keyword authentication_type: Authentication type. :paramtype authentication_type: str @@ -6351,7 +6112,7 @@ def __init__( request. :paramtype network_isolation: ~azure.mgmt.sql.models.NetworkIsolationSettings """ - super(ImportExistingDatabaseDefinition, self).__init__(**kwargs) + super().__init__(**kwargs) self.storage_key_type = storage_key_type self.storage_key = storage_key self.storage_uri = storage_uri @@ -6361,7 +6122,7 @@ def __init__( self.network_isolation = network_isolation -class ImportExportExtensionsOperationListResult(msrest.serialization.Model): +class ImportExportExtensionsOperationListResult(_serialization.Model): """Import export operation extensions list. Variables are only populated by the server, and will be ignored when sending a request. @@ -6373,22 +6134,18 @@ class ImportExportExtensionsOperationListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ImportExportExtensionsOperationResult]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ImportExportExtensionsOperationResult]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ImportExportExtensionsOperationListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -6421,38 +6178,34 @@ class ImportExportExtensionsOperationResult(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'request_id': {'readonly': True}, - 'request_type': {'readonly': True}, - 'last_modified_time': {'readonly': True}, - 'server_name': {'readonly': True}, - 'database_name': {'readonly': True}, - 'status': {'readonly': True}, - 'error_message': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "request_id": {"readonly": True}, + "request_type": {"readonly": True}, + "last_modified_time": {"readonly": True}, + "server_name": {"readonly": True}, + "database_name": {"readonly": True}, + "status": {"readonly": True}, + "error_message": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'request_id': {'key': 'properties.requestId', 'type': 'str'}, - 'request_type': {'key': 'properties.requestType', 'type': 'str'}, - 'last_modified_time': {'key': 'properties.lastModifiedTime', 'type': 'str'}, - 'server_name': {'key': 'properties.serverName', 'type': 'str'}, - 'database_name': {'key': 'properties.databaseName', 'type': 'str'}, - 'status': {'key': 'properties.status', 'type': 'str'}, - 'error_message': {'key': 'properties.errorMessage', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "request_id": {"key": "properties.requestId", "type": "str"}, + "request_type": {"key": "properties.requestType", "type": "str"}, + "last_modified_time": {"key": "properties.lastModifiedTime", "type": "str"}, + "server_name": {"key": "properties.serverName", "type": "str"}, + "database_name": {"key": "properties.databaseName", "type": "str"}, + "status": {"key": "properties.status", "type": "str"}, + "error_message": {"key": "properties.errorMessage", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ImportExportExtensionsOperationResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.request_id = None self.request_type = None self.last_modified_time = None @@ -6462,7 +6215,7 @@ def __init__( self.error_message = None -class ImportExportOperationResult(ProxyResource): +class ImportExportOperationResult(ProxyResource): # pylint: disable=too-many-instance-attributes """An ImportExport operation result resource. Variables are only populated by the server, and will be ignored when sending a request. @@ -6498,44 +6251,43 @@ class ImportExportOperationResult(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'request_id': {'readonly': True}, - 'request_type': {'readonly': True}, - 'queued_time': {'readonly': True}, - 'last_modified_time': {'readonly': True}, - 'blob_uri': {'readonly': True}, - 'server_name': {'readonly': True}, - 'database_name': {'readonly': True}, - 'status': {'readonly': True}, - 'error_message': {'readonly': True}, - 'private_endpoint_connections': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'request_id': {'key': 'properties.requestId', 'type': 'str'}, - 'request_type': {'key': 'properties.requestType', 'type': 'str'}, - 'queued_time': {'key': 'properties.queuedTime', 'type': 'str'}, - 'last_modified_time': {'key': 'properties.lastModifiedTime', 'type': 'str'}, - 'blob_uri': {'key': 'properties.blobUri', 'type': 'str'}, - 'server_name': {'key': 'properties.serverName', 'type': 'str'}, - 'database_name': {'key': 'properties.databaseName', 'type': 'str'}, - 'status': {'key': 'properties.status', 'type': 'str'}, - 'error_message': {'key': 'properties.errorMessage', 'type': 'str'}, - 'private_endpoint_connections': {'key': 'properties.privateEndpointConnections', 'type': '[PrivateEndpointConnectionRequestStatus]'}, - } - - def __init__( - self, - **kwargs - ): - """ - """ - super(ImportExportOperationResult, self).__init__(**kwargs) + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "request_id": {"readonly": True}, + "request_type": {"readonly": True}, + "queued_time": {"readonly": True}, + "last_modified_time": {"readonly": True}, + "blob_uri": {"readonly": True}, + "server_name": {"readonly": True}, + "database_name": {"readonly": True}, + "status": {"readonly": True}, + "error_message": {"readonly": True}, + "private_endpoint_connections": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "request_id": {"key": "properties.requestId", "type": "str"}, + "request_type": {"key": "properties.requestType", "type": "str"}, + "queued_time": {"key": "properties.queuedTime", "type": "str"}, + "last_modified_time": {"key": "properties.lastModifiedTime", "type": "str"}, + "blob_uri": {"key": "properties.blobUri", "type": "str"}, + "server_name": {"key": "properties.serverName", "type": "str"}, + "database_name": {"key": "properties.databaseName", "type": "str"}, + "status": {"key": "properties.status", "type": "str"}, + "error_message": {"key": "properties.errorMessage", "type": "str"}, + "private_endpoint_connections": { + "key": "properties.privateEndpointConnections", + "type": "[PrivateEndpointConnectionRequestStatus]", + }, + } + + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.request_id = None self.request_type = None self.queued_time = None @@ -6548,7 +6300,7 @@ def __init__( self.private_endpoint_connections = None -class ImportNewDatabaseDefinition(msrest.serialization.Model): +class ImportNewDatabaseDefinition(_serialization.Model): # pylint: disable=too-many-instance-attributes """Contains the information necessary to perform import operation for new database. All required parameters must be populated in order to send to Azure. @@ -6561,16 +6313,16 @@ class ImportNewDatabaseDefinition(msrest.serialization.Model): :vartype service_objective_name: str :ivar max_size_bytes: Max size in bytes for the import database. :vartype max_size_bytes: str - :ivar storage_key_type: Required. Storage key type. Known values are: "SharedAccessKey", + :ivar storage_key_type: Storage key type. Required. Known values are: "SharedAccessKey" and "StorageAccessKey". :vartype storage_key_type: str or ~azure.mgmt.sql.models.StorageKeyType - :ivar storage_key: Required. Storage key. + :ivar storage_key: Storage key. Required. :vartype storage_key: str - :ivar storage_uri: Required. Storage Uri. + :ivar storage_uri: Storage Uri. Required. :vartype storage_uri: str - :ivar administrator_login: Required. Administrator login name. + :ivar administrator_login: Administrator login name. Required. :vartype administrator_login: str - :ivar administrator_login_password: Required. Administrator login password. + :ivar administrator_login_password: Administrator login password. Required. :vartype administrator_login_password: str :ivar authentication_type: Authentication type. :vartype authentication_type: str @@ -6579,25 +6331,25 @@ class ImportNewDatabaseDefinition(msrest.serialization.Model): """ _validation = { - 'storage_key_type': {'required': True}, - 'storage_key': {'required': True}, - 'storage_uri': {'required': True}, - 'administrator_login': {'required': True}, - 'administrator_login_password': {'required': True}, + "storage_key_type": {"required": True}, + "storage_key": {"required": True}, + "storage_uri": {"required": True}, + "administrator_login": {"required": True}, + "administrator_login_password": {"required": True}, } _attribute_map = { - 'database_name': {'key': 'databaseName', 'type': 'str'}, - 'edition': {'key': 'edition', 'type': 'str'}, - 'service_objective_name': {'key': 'serviceObjectiveName', 'type': 'str'}, - 'max_size_bytes': {'key': 'maxSizeBytes', 'type': 'str'}, - 'storage_key_type': {'key': 'storageKeyType', 'type': 'str'}, - 'storage_key': {'key': 'storageKey', 'type': 'str'}, - 'storage_uri': {'key': 'storageUri', 'type': 'str'}, - 'administrator_login': {'key': 'administratorLogin', 'type': 'str'}, - 'administrator_login_password': {'key': 'administratorLoginPassword', 'type': 'str'}, - 'authentication_type': {'key': 'authenticationType', 'type': 'str'}, - 'network_isolation': {'key': 'networkIsolation', 'type': 'NetworkIsolationSettings'}, + "database_name": {"key": "databaseName", "type": "str"}, + "edition": {"key": "edition", "type": "str"}, + "service_objective_name": {"key": "serviceObjectiveName", "type": "str"}, + "max_size_bytes": {"key": "maxSizeBytes", "type": "str"}, + "storage_key_type": {"key": "storageKeyType", "type": "str"}, + "storage_key": {"key": "storageKey", "type": "str"}, + "storage_uri": {"key": "storageUri", "type": "str"}, + "administrator_login": {"key": "administratorLogin", "type": "str"}, + "administrator_login_password": {"key": "administratorLoginPassword", "type": "str"}, + "authentication_type": {"key": "authenticationType", "type": "str"}, + "network_isolation": {"key": "networkIsolation", "type": "NetworkIsolationSettings"}, } def __init__( @@ -6625,16 +6377,16 @@ def __init__( :paramtype service_objective_name: str :keyword max_size_bytes: Max size in bytes for the import database. :paramtype max_size_bytes: str - :keyword storage_key_type: Required. Storage key type. Known values are: "SharedAccessKey", + :keyword storage_key_type: Storage key type. Required. Known values are: "SharedAccessKey" and "StorageAccessKey". :paramtype storage_key_type: str or ~azure.mgmt.sql.models.StorageKeyType - :keyword storage_key: Required. Storage key. + :keyword storage_key: Storage key. Required. :paramtype storage_key: str - :keyword storage_uri: Required. Storage Uri. + :keyword storage_uri: Storage Uri. Required. :paramtype storage_uri: str - :keyword administrator_login: Required. Administrator login name. + :keyword administrator_login: Administrator login name. Required. :paramtype administrator_login: str - :keyword administrator_login_password: Required. Administrator login password. + :keyword administrator_login_password: Administrator login password. Required. :paramtype administrator_login_password: str :keyword authentication_type: Authentication type. :paramtype authentication_type: str @@ -6642,7 +6394,7 @@ def __init__( request. :paramtype network_isolation: ~azure.mgmt.sql.models.NetworkIsolationSettings """ - super(ImportNewDatabaseDefinition, self).__init__(**kwargs) + super().__init__(**kwargs) self.database_name = database_name self.edition = edition self.service_objective_name = service_objective_name @@ -6672,7 +6424,7 @@ class InstanceFailoverGroup(ProxyResource): :ivar read_only_endpoint: Read-only endpoint of the failover group instance. :vartype read_only_endpoint: ~azure.mgmt.sql.models.InstanceFailoverGroupReadOnlyEndpoint :ivar replication_role: Local replication role of the failover group instance. Known values - are: "Primary", "Secondary". + are: "Primary" and "Secondary". :vartype replication_role: str or ~azure.mgmt.sql.models.InstanceFailoverGroupReplicationRole :ivar replication_state: Replication state of the failover group instance. :vartype replication_state: str @@ -6683,23 +6435,26 @@ class InstanceFailoverGroup(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'replication_role': {'readonly': True}, - 'replication_state': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "replication_role": {"readonly": True}, + "replication_state": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'read_write_endpoint': {'key': 'properties.readWriteEndpoint', 'type': 'InstanceFailoverGroupReadWriteEndpoint'}, - 'read_only_endpoint': {'key': 'properties.readOnlyEndpoint', 'type': 'InstanceFailoverGroupReadOnlyEndpoint'}, - 'replication_role': {'key': 'properties.replicationRole', 'type': 'str'}, - 'replication_state': {'key': 'properties.replicationState', 'type': 'str'}, - 'partner_regions': {'key': 'properties.partnerRegions', 'type': '[PartnerRegionInfo]'}, - 'managed_instance_pairs': {'key': 'properties.managedInstancePairs', 'type': '[ManagedInstancePairInfo]'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "read_write_endpoint": { + "key": "properties.readWriteEndpoint", + "type": "InstanceFailoverGroupReadWriteEndpoint", + }, + "read_only_endpoint": {"key": "properties.readOnlyEndpoint", "type": "InstanceFailoverGroupReadOnlyEndpoint"}, + "replication_role": {"key": "properties.replicationRole", "type": "str"}, + "replication_state": {"key": "properties.replicationState", "type": "str"}, + "partner_regions": {"key": "properties.partnerRegions", "type": "[PartnerRegionInfo]"}, + "managed_instance_pairs": {"key": "properties.managedInstancePairs", "type": "[ManagedInstancePairInfo]"}, } def __init__( @@ -6721,7 +6476,7 @@ def __init__( :keyword managed_instance_pairs: List of managed instance pairs in the failover group. :paramtype managed_instance_pairs: list[~azure.mgmt.sql.models.ManagedInstancePairInfo] """ - super(InstanceFailoverGroup, self).__init__(**kwargs) + super().__init__(**kwargs) self.read_write_endpoint = read_write_endpoint self.read_only_endpoint = read_only_endpoint self.replication_role = None @@ -6730,7 +6485,7 @@ def __init__( self.managed_instance_pairs = managed_instance_pairs -class InstanceFailoverGroupListResult(msrest.serialization.Model): +class InstanceFailoverGroupListResult(_serialization.Model): """A list of instance failover groups. Variables are only populated by the server, and will be ignored when sending a request. @@ -6742,61 +6497,54 @@ class InstanceFailoverGroupListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[InstanceFailoverGroup]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[InstanceFailoverGroup]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(InstanceFailoverGroupListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class InstanceFailoverGroupReadOnlyEndpoint(msrest.serialization.Model): +class InstanceFailoverGroupReadOnlyEndpoint(_serialization.Model): """Read-only endpoint of the failover group instance. :ivar failover_policy: Failover policy of the read-only endpoint for the failover group. Known - values are: "Disabled", "Enabled". + values are: "Disabled" and "Enabled". :vartype failover_policy: str or ~azure.mgmt.sql.models.ReadOnlyEndpointFailoverPolicy """ _attribute_map = { - 'failover_policy': {'key': 'failoverPolicy', 'type': 'str'}, + "failover_policy": {"key": "failoverPolicy", "type": "str"}, } def __init__( - self, - *, - failover_policy: Optional[Union[str, "_models.ReadOnlyEndpointFailoverPolicy"]] = None, - **kwargs + self, *, failover_policy: Optional[Union[str, "_models.ReadOnlyEndpointFailoverPolicy"]] = None, **kwargs ): """ :keyword failover_policy: Failover policy of the read-only endpoint for the failover group. - Known values are: "Disabled", "Enabled". + Known values are: "Disabled" and "Enabled". :paramtype failover_policy: str or ~azure.mgmt.sql.models.ReadOnlyEndpointFailoverPolicy """ - super(InstanceFailoverGroupReadOnlyEndpoint, self).__init__(**kwargs) + super().__init__(**kwargs) self.failover_policy = failover_policy -class InstanceFailoverGroupReadWriteEndpoint(msrest.serialization.Model): +class InstanceFailoverGroupReadWriteEndpoint(_serialization.Model): """Read-write endpoint of the failover group instance. All required parameters must be populated in order to send to Azure. - :ivar failover_policy: Required. Failover policy of the read-write endpoint for the failover - group. If failoverPolicy is Automatic then failoverWithDataLossGracePeriodMinutes is required. - Known values are: "Manual", "Automatic". + :ivar failover_policy: Failover policy of the read-write endpoint for the failover group. If + failoverPolicy is Automatic then failoverWithDataLossGracePeriodMinutes is required. Required. + Known values are: "Manual" and "Automatic". :vartype failover_policy: str or ~azure.mgmt.sql.models.ReadWriteEndpointFailoverPolicy :ivar failover_with_data_loss_grace_period_minutes: Grace period before failover with data loss is attempted for the read-write endpoint. If failoverPolicy is Automatic then @@ -6805,12 +6553,15 @@ class InstanceFailoverGroupReadWriteEndpoint(msrest.serialization.Model): """ _validation = { - 'failover_policy': {'required': True}, + "failover_policy": {"required": True}, } _attribute_map = { - 'failover_policy': {'key': 'failoverPolicy', 'type': 'str'}, - 'failover_with_data_loss_grace_period_minutes': {'key': 'failoverWithDataLossGracePeriodMinutes', 'type': 'int'}, + "failover_policy": {"key": "failoverPolicy", "type": "str"}, + "failover_with_data_loss_grace_period_minutes": { + "key": "failoverWithDataLossGracePeriodMinutes", + "type": "int", + }, } def __init__( @@ -6821,16 +6572,16 @@ def __init__( **kwargs ): """ - :keyword failover_policy: Required. Failover policy of the read-write endpoint for the failover - group. If failoverPolicy is Automatic then failoverWithDataLossGracePeriodMinutes is required. - Known values are: "Manual", "Automatic". + :keyword failover_policy: Failover policy of the read-write endpoint for the failover group. If + failoverPolicy is Automatic then failoverWithDataLossGracePeriodMinutes is required. Required. + Known values are: "Manual" and "Automatic". :paramtype failover_policy: str or ~azure.mgmt.sql.models.ReadWriteEndpointFailoverPolicy :keyword failover_with_data_loss_grace_period_minutes: Grace period before failover with data loss is attempted for the read-write endpoint. If failoverPolicy is Automatic then failoverWithDataLossGracePeriodMinutes is required. :paramtype failover_with_data_loss_grace_period_minutes: int """ - super(InstanceFailoverGroupReadWriteEndpoint, self).__init__(**kwargs) + super().__init__(**kwargs) self.failover_policy = failover_policy self.failover_with_data_loss_grace_period_minutes = failover_with_data_loss_grace_period_minutes @@ -6848,9 +6599,9 @@ class InstancePool(TrackedResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar location: Required. Resource location. + :ivar location: Resource location. Required. :vartype location: str - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar sku: The name and tier of the SKU. :vartype sku: ~azure.mgmt.sql.models.Sku @@ -6860,27 +6611,27 @@ class InstancePool(TrackedResource): :vartype v_cores: int :ivar license_type: The license type. Possible values are 'LicenseIncluded' (price for SQL license is included) and 'BasePrice' (without SQL license price). Known values are: - "LicenseIncluded", "BasePrice". + "LicenseIncluded" and "BasePrice". :vartype license_type: str or ~azure.mgmt.sql.models.InstancePoolLicenseType """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'location': {'required': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "location": {"required": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'tags': {'key': 'tags', 'type': '{str}'}, - 'sku': {'key': 'sku', 'type': 'Sku'}, - 'subnet_id': {'key': 'properties.subnetId', 'type': 'str'}, - 'v_cores': {'key': 'properties.vCores', 'type': 'int'}, - 'license_type': {'key': 'properties.licenseType', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "tags": {"key": "tags", "type": "{str}"}, + "sku": {"key": "sku", "type": "Sku"}, + "subnet_id": {"key": "properties.subnetId", "type": "str"}, + "v_cores": {"key": "properties.vCores", "type": "int"}, + "license_type": {"key": "properties.licenseType", "type": "str"}, } def __init__( @@ -6895,9 +6646,9 @@ def __init__( **kwargs ): """ - :keyword location: Required. Resource location. + :keyword location: Resource location. Required. :paramtype location: str - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] :keyword sku: The name and tier of the SKU. :paramtype sku: ~azure.mgmt.sql.models.Sku @@ -6907,17 +6658,17 @@ def __init__( :paramtype v_cores: int :keyword license_type: The license type. Possible values are 'LicenseIncluded' (price for SQL license is included) and 'BasePrice' (without SQL license price). Known values are: - "LicenseIncluded", "BasePrice". + "LicenseIncluded" and "BasePrice". :paramtype license_type: str or ~azure.mgmt.sql.models.InstancePoolLicenseType """ - super(InstancePool, self).__init__(location=location, tags=tags, **kwargs) + super().__init__(location=location, tags=tags, **kwargs) self.sku = sku self.subnet_id = subnet_id self.v_cores = v_cores self.license_type = license_type -class InstancePoolEditionCapability(msrest.serialization.Model): +class InstancePoolEditionCapability(_serialization.Model): """The instance pool capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -6927,43 +6678,38 @@ class InstancePoolEditionCapability(msrest.serialization.Model): :ivar supported_families: The supported families. :vartype supported_families: list[~azure.mgmt.sql.models.InstancePoolFamilyCapability] :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'name': {'readonly': True}, - 'supported_families': {'readonly': True}, - 'status': {'readonly': True}, + "name": {"readonly": True}, + "supported_families": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'supported_families': {'key': 'supportedFamilies', 'type': '[InstancePoolFamilyCapability]'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "name": {"key": "name", "type": "str"}, + "supported_families": {"key": "supportedFamilies", "type": "[InstancePoolFamilyCapability]"}, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(InstancePoolEditionCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.name = None self.supported_families = None self.status = None self.reason = reason -class InstancePoolFamilyCapability(msrest.serialization.Model): +class InstancePoolFamilyCapability(_serialization.Model): """The instance pool family capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -6975,38 +6721,33 @@ class InstancePoolFamilyCapability(msrest.serialization.Model): :ivar supported_vcores_values: List of supported virtual cores values. :vartype supported_vcores_values: list[~azure.mgmt.sql.models.InstancePoolVcoresCapability] :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'name': {'readonly': True}, - 'supported_license_types': {'readonly': True}, - 'supported_vcores_values': {'readonly': True}, - 'status': {'readonly': True}, + "name": {"readonly": True}, + "supported_license_types": {"readonly": True}, + "supported_vcores_values": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'supported_license_types': {'key': 'supportedLicenseTypes', 'type': '[LicenseTypeCapability]'}, - 'supported_vcores_values': {'key': 'supportedVcoresValues', 'type': '[InstancePoolVcoresCapability]'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "name": {"key": "name", "type": "str"}, + "supported_license_types": {"key": "supportedLicenseTypes", "type": "[LicenseTypeCapability]"}, + "supported_vcores_values": {"key": "supportedVcoresValues", "type": "[InstancePoolVcoresCapability]"}, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(InstancePoolFamilyCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.name = None self.supported_license_types = None self.supported_vcores_values = None @@ -7014,7 +6755,7 @@ def __init__( self.reason = reason -class InstancePoolListResult(msrest.serialization.Model): +class InstancePoolListResult(_serialization.Model): """A list of Azure SQL instance pools. Variables are only populated by the server, and will be ignored when sending a request. @@ -7026,52 +6767,43 @@ class InstancePoolListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[InstancePool]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[InstancePool]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(InstancePoolListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class InstancePoolUpdate(msrest.serialization.Model): +class InstancePoolUpdate(_serialization.Model): """An update to an Instance pool. - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] """ _attribute_map = { - 'tags': {'key': 'tags', 'type': '{str}'}, + "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): """ - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] """ - super(InstancePoolUpdate, self).__init__(**kwargs) + super().__init__(**kwargs) self.tags = tags -class InstancePoolVcoresCapability(msrest.serialization.Model): +class InstancePoolVcoresCapability(_serialization.Model): """The managed instance virtual cores capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -7083,38 +6815,33 @@ class InstancePoolVcoresCapability(msrest.serialization.Model): :ivar storage_limit: Storage limit. :vartype storage_limit: ~azure.mgmt.sql.models.MaxSizeCapability :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'name': {'readonly': True}, - 'value': {'readonly': True}, - 'storage_limit': {'readonly': True}, - 'status': {'readonly': True}, + "name": {"readonly": True}, + "value": {"readonly": True}, + "storage_limit": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'value': {'key': 'value', 'type': 'int'}, - 'storage_limit': {'key': 'storageLimit', 'type': 'MaxSizeCapability'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "name": {"key": "name", "type": "str"}, + "value": {"key": "value", "type": "int"}, + "storage_limit": {"key": "storageLimit", "type": "MaxSizeCapability"}, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(InstancePoolVcoresCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.name = None self.value = None self.storage_limit = None @@ -7141,16 +6868,16 @@ class IPv6FirewallRule(ProxyResourceWithWritableName): """ _validation = { - 'id': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'start_i_pv6_address': {'key': 'properties.startIPv6Address', 'type': 'str'}, - 'end_i_pv6_address': {'key': 'properties.endIPv6Address', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "start_i_pv6_address": {"key": "properties.startIPv6Address", "type": "str"}, + "end_i_pv6_address": {"key": "properties.endIPv6Address", "type": "str"}, } def __init__( @@ -7170,12 +6897,12 @@ def __init__( be greater than or equal to startIpAddress. :paramtype end_i_pv6_address: str """ - super(IPv6FirewallRule, self).__init__(name=name, **kwargs) + super().__init__(name=name, **kwargs) self.start_i_pv6_address = start_i_pv6_address self.end_i_pv6_address = end_i_pv6_address -class IPv6FirewallRuleListResult(msrest.serialization.Model): +class IPv6FirewallRuleListResult(_serialization.Model): """The response to a list IPv6 firewall rules request. Variables are only populated by the server, and will be ignored when sending a request. @@ -7187,22 +6914,18 @@ class IPv6FirewallRuleListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[IPv6FirewallRule]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[IPv6FirewallRule]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(IPv6FirewallRuleListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -7227,35 +6950,29 @@ class Job(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'version': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "version": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'description': {'key': 'properties.description', 'type': 'str'}, - 'version': {'key': 'properties.version', 'type': 'int'}, - 'schedule': {'key': 'properties.schedule', 'type': 'JobSchedule'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "description": {"key": "properties.description", "type": "str"}, + "version": {"key": "properties.version", "type": "int"}, + "schedule": {"key": "properties.schedule", "type": "JobSchedule"}, } - def __init__( - self, - *, - description: Optional[str] = "", - schedule: Optional["_models.JobSchedule"] = None, - **kwargs - ): + def __init__(self, *, description: str = "", schedule: Optional["_models.JobSchedule"] = None, **kwargs): """ :keyword description: User-defined description of the job. :paramtype description: str :keyword schedule: Schedule properties of the job. :paramtype schedule: ~azure.mgmt.sql.models.JobSchedule """ - super(Job, self).__init__(**kwargs) + super().__init__(**kwargs) self.description = description self.version = None self.schedule = schedule @@ -7274,36 +6991,36 @@ class JobAgent(TrackedResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar location: Required. Resource location. + :ivar location: Resource location. Required. :vartype location: str - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar sku: The name and tier of the SKU. :vartype sku: ~azure.mgmt.sql.models.Sku :ivar database_id: Resource ID of the database to store job metadata in. :vartype database_id: str :ivar state: The state of the job agent. Known values are: "Creating", "Ready", "Updating", - "Deleting", "Disabled". + "Deleting", and "Disabled". :vartype state: str or ~azure.mgmt.sql.models.JobAgentState """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'location': {'required': True}, - 'state': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "location": {"required": True}, + "state": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'tags': {'key': 'tags', 'type': '{str}'}, - 'sku': {'key': 'sku', 'type': 'Sku'}, - 'database_id': {'key': 'properties.databaseId', 'type': 'str'}, - 'state': {'key': 'properties.state', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "tags": {"key": "tags", "type": "{str}"}, + "sku": {"key": "sku", "type": "Sku"}, + "database_id": {"key": "properties.databaseId", "type": "str"}, + "state": {"key": "properties.state", "type": "str"}, } def __init__( @@ -7316,22 +7033,22 @@ def __init__( **kwargs ): """ - :keyword location: Required. Resource location. + :keyword location: Resource location. Required. :paramtype location: str - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] :keyword sku: The name and tier of the SKU. :paramtype sku: ~azure.mgmt.sql.models.Sku :keyword database_id: Resource ID of the database to store job metadata in. :paramtype database_id: str """ - super(JobAgent, self).__init__(location=location, tags=tags, **kwargs) + super().__init__(location=location, tags=tags, **kwargs) self.sku = sku self.database_id = database_id self.state = None -class JobAgentListResult(msrest.serialization.Model): +class JobAgentListResult(_serialization.Model): """A list of Azure SQL job agents. Variables are only populated by the server, and will be ignored when sending a request. @@ -7343,48 +7060,39 @@ class JobAgentListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[JobAgent]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[JobAgent]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(JobAgentListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class JobAgentUpdate(msrest.serialization.Model): +class JobAgentUpdate(_serialization.Model): """An update to an Azure SQL job agent. - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] """ _attribute_map = { - 'tags': {'key': 'tags', 'type': '{str}'}, + "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): """ - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] """ - super(JobAgentUpdate, self).__init__(**kwargs) + super().__init__(**kwargs) self.tags = tags @@ -7406,38 +7114,32 @@ class JobCredential(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'username': {'key': 'properties.username', 'type': 'str'}, - 'password': {'key': 'properties.password', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "username": {"key": "properties.username", "type": "str"}, + "password": {"key": "properties.password", "type": "str"}, } - def __init__( - self, - *, - username: Optional[str] = None, - password: Optional[str] = None, - **kwargs - ): + def __init__(self, *, username: Optional[str] = None, password: Optional[str] = None, **kwargs): """ :keyword username: The credential user name. :paramtype username: str :keyword password: The credential password. :paramtype password: str """ - super(JobCredential, self).__init__(**kwargs) + super().__init__(**kwargs) self.username = username self.password = password -class JobCredentialListResult(msrest.serialization.Model): +class JobCredentialListResult(_serialization.Model): """A list of job credentials. Variables are only populated by the server, and will be ignored when sending a request. @@ -7449,27 +7151,23 @@ class JobCredentialListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[JobCredential]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[JobCredential]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(JobCredentialListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class JobExecution(ProxyResource): +class JobExecution(ProxyResource): # pylint: disable=too-many-instance-attributes """An execution of a job. Variables are only populated by the server, and will be ignored when sending a request. @@ -7490,10 +7188,10 @@ class JobExecution(ProxyResource): :vartype job_execution_id: str :ivar lifecycle: The detailed state of the job execution. Known values are: "Created", "InProgress", "WaitingForChildJobExecutions", "WaitingForRetry", "Succeeded", - "SucceededWithSkipped", "Failed", "TimedOut", "Canceled", "Skipped". + "SucceededWithSkipped", "Failed", "TimedOut", "Canceled", and "Skipped". :vartype lifecycle: str or ~azure.mgmt.sql.models.JobExecutionLifecycle :ivar provisioning_state: The ARM provisioning state of the job execution. Known values are: - "Created", "InProgress", "Succeeded", "Failed", "Canceled". + "Created", "InProgress", "Succeeded", "Failed", and "Canceled". :vartype provisioning_state: str or ~azure.mgmt.sql.models.ProvisioningState :ivar create_time: The time that the job execution was created. :vartype create_time: ~datetime.datetime @@ -7512,53 +7210,48 @@ class JobExecution(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'job_version': {'readonly': True}, - 'step_name': {'readonly': True}, - 'step_id': {'readonly': True}, - 'job_execution_id': {'readonly': True}, - 'lifecycle': {'readonly': True}, - 'provisioning_state': {'readonly': True}, - 'create_time': {'readonly': True}, - 'start_time': {'readonly': True}, - 'end_time': {'readonly': True}, - 'current_attempt_start_time': {'readonly': True}, - 'last_message': {'readonly': True}, - 'target': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'job_version': {'key': 'properties.jobVersion', 'type': 'int'}, - 'step_name': {'key': 'properties.stepName', 'type': 'str'}, - 'step_id': {'key': 'properties.stepId', 'type': 'int'}, - 'job_execution_id': {'key': 'properties.jobExecutionId', 'type': 'str'}, - 'lifecycle': {'key': 'properties.lifecycle', 'type': 'str'}, - 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, - 'create_time': {'key': 'properties.createTime', 'type': 'iso-8601'}, - 'start_time': {'key': 'properties.startTime', 'type': 'iso-8601'}, - 'end_time': {'key': 'properties.endTime', 'type': 'iso-8601'}, - 'current_attempts': {'key': 'properties.currentAttempts', 'type': 'int'}, - 'current_attempt_start_time': {'key': 'properties.currentAttemptStartTime', 'type': 'iso-8601'}, - 'last_message': {'key': 'properties.lastMessage', 'type': 'str'}, - 'target': {'key': 'properties.target', 'type': 'JobExecutionTarget'}, - } - - def __init__( - self, - *, - current_attempts: Optional[int] = None, - **kwargs - ): + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "job_version": {"readonly": True}, + "step_name": {"readonly": True}, + "step_id": {"readonly": True}, + "job_execution_id": {"readonly": True}, + "lifecycle": {"readonly": True}, + "provisioning_state": {"readonly": True}, + "create_time": {"readonly": True}, + "start_time": {"readonly": True}, + "end_time": {"readonly": True}, + "current_attempt_start_time": {"readonly": True}, + "last_message": {"readonly": True}, + "target": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "job_version": {"key": "properties.jobVersion", "type": "int"}, + "step_name": {"key": "properties.stepName", "type": "str"}, + "step_id": {"key": "properties.stepId", "type": "int"}, + "job_execution_id": {"key": "properties.jobExecutionId", "type": "str"}, + "lifecycle": {"key": "properties.lifecycle", "type": "str"}, + "provisioning_state": {"key": "properties.provisioningState", "type": "str"}, + "create_time": {"key": "properties.createTime", "type": "iso-8601"}, + "start_time": {"key": "properties.startTime", "type": "iso-8601"}, + "end_time": {"key": "properties.endTime", "type": "iso-8601"}, + "current_attempts": {"key": "properties.currentAttempts", "type": "int"}, + "current_attempt_start_time": {"key": "properties.currentAttemptStartTime", "type": "iso-8601"}, + "last_message": {"key": "properties.lastMessage", "type": "str"}, + "target": {"key": "properties.target", "type": "JobExecutionTarget"}, + } + + def __init__(self, *, current_attempts: Optional[int] = None, **kwargs): """ :keyword current_attempts: Number of times the job execution has been attempted. :paramtype current_attempts: int """ - super(JobExecution, self).__init__(**kwargs) + super().__init__(**kwargs) self.job_version = None self.step_name = None self.step_id = None @@ -7574,7 +7267,7 @@ def __init__( self.target = None -class JobExecutionListResult(msrest.serialization.Model): +class JobExecutionListResult(_serialization.Model): """A list of job executions. Variables are only populated by the server, and will be ignored when sending a request. @@ -7586,33 +7279,29 @@ class JobExecutionListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[JobExecution]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[JobExecution]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(JobExecutionListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class JobExecutionTarget(msrest.serialization.Model): +class JobExecutionTarget(_serialization.Model): """The target that a job execution is executed on. Variables are only populated by the server, and will be ignored when sending a request. :ivar type: The type of the target. Known values are: "TargetGroup", "SqlDatabase", - "SqlElasticPool", "SqlShardMap", "SqlServer". + "SqlElasticPool", "SqlShardMap", and "SqlServer". :vartype type: str or ~azure.mgmt.sql.models.JobTargetType :ivar server_name: The server name. :vartype server_name: str @@ -7621,30 +7310,26 @@ class JobExecutionTarget(msrest.serialization.Model): """ _validation = { - 'type': {'readonly': True}, - 'server_name': {'readonly': True}, - 'database_name': {'readonly': True}, + "type": {"readonly": True}, + "server_name": {"readonly": True}, + "database_name": {"readonly": True}, } _attribute_map = { - 'type': {'key': 'type', 'type': 'str'}, - 'server_name': {'key': 'serverName', 'type': 'str'}, - 'database_name': {'key': 'databaseName', 'type': 'str'}, + "type": {"key": "type", "type": "str"}, + "server_name": {"key": "serverName", "type": "str"}, + "database_name": {"key": "databaseName", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(JobExecutionTarget, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.type = None self.server_name = None self.database_name = None -class JobListResult(msrest.serialization.Model): +class JobListResult(_serialization.Model): """A list of jobs. Variables are only populated by the server, and will be ignored when sending a request. @@ -7656,35 +7341,30 @@ class JobListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[Job]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[Job]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(JobListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class JobSchedule(msrest.serialization.Model): +class JobSchedule(_serialization.Model): """Scheduling properties of a job. :ivar start_time: Schedule start time. :vartype start_time: ~datetime.datetime :ivar end_time: Schedule end time. :vartype end_time: ~datetime.datetime - :ivar type: Schedule interval type. Known values are: "Once", "Recurring". Default value: - "Once". + :ivar type: Schedule interval type. Known values are: "Once" and "Recurring". :vartype type: str or ~azure.mgmt.sql.models.JobScheduleType :ivar enabled: Whether or not the schedule is enabled. :vartype enabled: bool @@ -7694,19 +7374,19 @@ class JobSchedule(msrest.serialization.Model): """ _attribute_map = { - 'start_time': {'key': 'startTime', 'type': 'iso-8601'}, - 'end_time': {'key': 'endTime', 'type': 'iso-8601'}, - 'type': {'key': 'type', 'type': 'str'}, - 'enabled': {'key': 'enabled', 'type': 'bool'}, - 'interval': {'key': 'interval', 'type': 'str'}, + "start_time": {"key": "startTime", "type": "iso-8601"}, + "end_time": {"key": "endTime", "type": "iso-8601"}, + "type": {"key": "type", "type": "str"}, + "enabled": {"key": "enabled", "type": "bool"}, + "interval": {"key": "interval", "type": "str"}, } def __init__( self, *, - start_time: Optional[datetime.datetime] = "0001-01-01T00:00:00+00:00", - end_time: Optional[datetime.datetime] = "9999-12-31T11:59:59+00:00", - type: Optional[Union[str, "_models.JobScheduleType"]] = "Once", + start_time: datetime.datetime = "0001-01-01T00:00:00+00:00", + end_time: datetime.datetime = "9999-12-31T11:59:59+00:00", + type: Union[str, "_models.JobScheduleType"] = "Once", enabled: Optional[bool] = None, interval: Optional[str] = None, **kwargs @@ -7716,8 +7396,7 @@ def __init__( :paramtype start_time: ~datetime.datetime :keyword end_time: Schedule end time. :paramtype end_time: ~datetime.datetime - :keyword type: Schedule interval type. Known values are: "Once", "Recurring". Default value: - "Once". + :keyword type: Schedule interval type. Known values are: "Once" and "Recurring". :paramtype type: str or ~azure.mgmt.sql.models.JobScheduleType :keyword enabled: Whether or not the schedule is enabled. :paramtype enabled: bool @@ -7725,7 +7404,7 @@ def __init__( recurring. ISO8601 duration format. :paramtype interval: str """ - super(JobSchedule, self).__init__(**kwargs) + super().__init__(**kwargs) self.start_time = start_time self.end_time = end_time self.type = type @@ -7762,21 +7441,21 @@ class JobStep(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'step_id': {'key': 'properties.stepId', 'type': 'int'}, - 'target_group': {'key': 'properties.targetGroup', 'type': 'str'}, - 'credential': {'key': 'properties.credential', 'type': 'str'}, - 'action': {'key': 'properties.action', 'type': 'JobStepAction'}, - 'output': {'key': 'properties.output', 'type': 'JobStepOutput'}, - 'execution_options': {'key': 'properties.executionOptions', 'type': 'JobStepExecutionOptions'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "step_id": {"key": "properties.stepId", "type": "int"}, + "target_group": {"key": "properties.targetGroup", "type": "str"}, + "credential": {"key": "properties.credential", "type": "str"}, + "action": {"key": "properties.action", "type": "JobStepAction"}, + "output": {"key": "properties.output", "type": "JobStepOutput"}, + "execution_options": {"key": "properties.executionOptions", "type": "JobStepExecutionOptions"}, } def __init__( @@ -7808,7 +7487,7 @@ def __init__( :keyword execution_options: Execution options for the job step. :paramtype execution_options: ~azure.mgmt.sql.models.JobStepExecutionOptions """ - super(JobStep, self).__init__(**kwargs) + super().__init__(**kwargs) self.step_id = step_id self.target_group = target_group self.credential = credential @@ -7817,57 +7496,53 @@ def __init__( self.execution_options = execution_options -class JobStepAction(msrest.serialization.Model): +class JobStepAction(_serialization.Model): """The action to be executed by a job step. All required parameters must be populated in order to send to Azure. - :ivar type: Type of action being executed by the job step. Known values are: "TSql". Default - value: "TSql". + :ivar type: Type of action being executed by the job step. "TSql" :vartype type: str or ~azure.mgmt.sql.models.JobStepActionType - :ivar source: The source of the action to execute. Known values are: "Inline". Default value: - "Inline". + :ivar source: The source of the action to execute. "Inline" :vartype source: str or ~azure.mgmt.sql.models.JobStepActionSource - :ivar value: Required. The action value, for example the text of the T-SQL script to execute. + :ivar value: The action value, for example the text of the T-SQL script to execute. Required. :vartype value: str """ _validation = { - 'value': {'required': True}, + "value": {"required": True}, } _attribute_map = { - 'type': {'key': 'type', 'type': 'str'}, - 'source': {'key': 'source', 'type': 'str'}, - 'value': {'key': 'value', 'type': 'str'}, + "type": {"key": "type", "type": "str"}, + "source": {"key": "source", "type": "str"}, + "value": {"key": "value", "type": "str"}, } def __init__( self, *, value: str, - type: Optional[Union[str, "_models.JobStepActionType"]] = "TSql", - source: Optional[Union[str, "_models.JobStepActionSource"]] = "Inline", + type: Union[str, "_models.JobStepActionType"] = "TSql", + source: Union[str, "_models.JobStepActionSource"] = "Inline", **kwargs ): """ - :keyword type: Type of action being executed by the job step. Known values are: "TSql". Default - value: "TSql". + :keyword type: Type of action being executed by the job step. "TSql" :paramtype type: str or ~azure.mgmt.sql.models.JobStepActionType - :keyword source: The source of the action to execute. Known values are: "Inline". Default - value: "Inline". + :keyword source: The source of the action to execute. "Inline" :paramtype source: str or ~azure.mgmt.sql.models.JobStepActionSource - :keyword value: Required. The action value, for example the text of the T-SQL script to - execute. + :keyword value: The action value, for example the text of the T-SQL script to execute. + Required. :paramtype value: str """ - super(JobStepAction, self).__init__(**kwargs) + super().__init__(**kwargs) self.type = type self.source = source self.value = value -class JobStepExecutionOptions(msrest.serialization.Model): +class JobStepExecutionOptions(_serialization.Model): """The execution options of a job step. :ivar timeout_seconds: Execution timeout for the job step. @@ -7885,21 +7560,21 @@ class JobStepExecutionOptions(msrest.serialization.Model): """ _attribute_map = { - 'timeout_seconds': {'key': 'timeoutSeconds', 'type': 'int'}, - 'retry_attempts': {'key': 'retryAttempts', 'type': 'int'}, - 'initial_retry_interval_seconds': {'key': 'initialRetryIntervalSeconds', 'type': 'int'}, - 'maximum_retry_interval_seconds': {'key': 'maximumRetryIntervalSeconds', 'type': 'int'}, - 'retry_interval_backoff_multiplier': {'key': 'retryIntervalBackoffMultiplier', 'type': 'float'}, + "timeout_seconds": {"key": "timeoutSeconds", "type": "int"}, + "retry_attempts": {"key": "retryAttempts", "type": "int"}, + "initial_retry_interval_seconds": {"key": "initialRetryIntervalSeconds", "type": "int"}, + "maximum_retry_interval_seconds": {"key": "maximumRetryIntervalSeconds", "type": "int"}, + "retry_interval_backoff_multiplier": {"key": "retryIntervalBackoffMultiplier", "type": "float"}, } def __init__( self, *, - timeout_seconds: Optional[int] = 43200, - retry_attempts: Optional[int] = 10, - initial_retry_interval_seconds: Optional[int] = 1, - maximum_retry_interval_seconds: Optional[int] = 120, - retry_interval_backoff_multiplier: Optional[float] = 2, + timeout_seconds: int = 43200, + retry_attempts: int = 10, + initial_retry_interval_seconds: int = 1, + maximum_retry_interval_seconds: int = 120, + retry_interval_backoff_multiplier: float = 2, **kwargs ): """ @@ -7917,7 +7592,7 @@ def __init__( retries. :paramtype retry_interval_backoff_multiplier: float """ - super(JobStepExecutionOptions, self).__init__(**kwargs) + super().__init__(**kwargs) self.timeout_seconds = timeout_seconds self.retry_attempts = retry_attempts self.initial_retry_interval_seconds = initial_retry_interval_seconds @@ -7925,7 +7600,7 @@ def __init__( self.retry_interval_backoff_multiplier = retry_interval_backoff_multiplier -class JobStepListResult(msrest.serialization.Model): +class JobStepListResult(_serialization.Model): """A list of job steps. Variables are only populated by the server, and will be ignored when sending a request. @@ -7937,67 +7612,62 @@ class JobStepListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[JobStep]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[JobStep]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(JobStepListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class JobStepOutput(msrest.serialization.Model): +class JobStepOutput(_serialization.Model): """The output configuration of a job step. All required parameters must be populated in order to send to Azure. - :ivar type: The output destination type. Known values are: "SqlDatabase". Default value: - "SqlDatabase". + :ivar type: The output destination type. "SqlDatabase" :vartype type: str or ~azure.mgmt.sql.models.JobStepOutputType :ivar subscription_id: The output destination subscription id. :vartype subscription_id: str :ivar resource_group_name: The output destination resource group. :vartype resource_group_name: str - :ivar server_name: Required. The output destination server name. + :ivar server_name: The output destination server name. Required. :vartype server_name: str - :ivar database_name: Required. The output destination database. + :ivar database_name: The output destination database. Required. :vartype database_name: str :ivar schema_name: The output destination schema. :vartype schema_name: str - :ivar table_name: Required. The output destination table. + :ivar table_name: The output destination table. Required. :vartype table_name: str - :ivar credential: Required. The resource ID of the credential to use to connect to the output - destination. + :ivar credential: The resource ID of the credential to use to connect to the output + destination. Required. :vartype credential: str """ _validation = { - 'server_name': {'required': True}, - 'database_name': {'required': True}, - 'table_name': {'required': True}, - 'credential': {'required': True}, + "server_name": {"required": True}, + "database_name": {"required": True}, + "table_name": {"required": True}, + "credential": {"required": True}, } _attribute_map = { - 'type': {'key': 'type', 'type': 'str'}, - 'subscription_id': {'key': 'subscriptionId', 'type': 'str'}, - 'resource_group_name': {'key': 'resourceGroupName', 'type': 'str'}, - 'server_name': {'key': 'serverName', 'type': 'str'}, - 'database_name': {'key': 'databaseName', 'type': 'str'}, - 'schema_name': {'key': 'schemaName', 'type': 'str'}, - 'table_name': {'key': 'tableName', 'type': 'str'}, - 'credential': {'key': 'credential', 'type': 'str'}, + "type": {"key": "type", "type": "str"}, + "subscription_id": {"key": "subscriptionId", "type": "str"}, + "resource_group_name": {"key": "resourceGroupName", "type": "str"}, + "server_name": {"key": "serverName", "type": "str"}, + "database_name": {"key": "databaseName", "type": "str"}, + "schema_name": {"key": "schemaName", "type": "str"}, + "table_name": {"key": "tableName", "type": "str"}, + "credential": {"key": "credential", "type": "str"}, } def __init__( @@ -8007,33 +7677,32 @@ def __init__( database_name: str, table_name: str, credential: str, - type: Optional[Union[str, "_models.JobStepOutputType"]] = "SqlDatabase", + type: Union[str, "_models.JobStepOutputType"] = "SqlDatabase", subscription_id: Optional[str] = None, resource_group_name: Optional[str] = None, - schema_name: Optional[str] = "dbo", + schema_name: str = "dbo", **kwargs ): """ - :keyword type: The output destination type. Known values are: "SqlDatabase". Default value: - "SqlDatabase". + :keyword type: The output destination type. "SqlDatabase" :paramtype type: str or ~azure.mgmt.sql.models.JobStepOutputType :keyword subscription_id: The output destination subscription id. :paramtype subscription_id: str :keyword resource_group_name: The output destination resource group. :paramtype resource_group_name: str - :keyword server_name: Required. The output destination server name. + :keyword server_name: The output destination server name. Required. :paramtype server_name: str - :keyword database_name: Required. The output destination database. + :keyword database_name: The output destination database. Required. :paramtype database_name: str :keyword schema_name: The output destination schema. :paramtype schema_name: str - :keyword table_name: Required. The output destination table. + :keyword table_name: The output destination table. Required. :paramtype table_name: str - :keyword credential: Required. The resource ID of the credential to use to connect to the - output destination. + :keyword credential: The resource ID of the credential to use to connect to the output + destination. Required. :paramtype credential: str """ - super(JobStepOutput, self).__init__(**kwargs) + super().__init__(**kwargs) self.type = type self.subscription_id = subscription_id self.resource_group_name = resource_group_name @@ -8044,16 +7713,16 @@ def __init__( self.credential = credential -class JobTarget(msrest.serialization.Model): +class JobTarget(_serialization.Model): """A job target, for example a specific database or a container of databases that is evaluated during job execution. All required parameters must be populated in order to send to Azure. :ivar membership_type: Whether the target is included or excluded from the group. Known values - are: "Include", "Exclude". Default value: "Include". + are: "Include" and "Exclude". :vartype membership_type: str or ~azure.mgmt.sql.models.JobTargetGroupMembershipType - :ivar type: Required. The target type. Known values are: "TargetGroup", "SqlDatabase", - "SqlElasticPool", "SqlShardMap", "SqlServer". + :ivar type: The target type. Required. Known values are: "TargetGroup", "SqlDatabase", + "SqlElasticPool", "SqlShardMap", and "SqlServer". :vartype type: str or ~azure.mgmt.sql.models.JobTargetType :ivar server_name: The target server name. :vartype server_name: str @@ -8069,24 +7738,24 @@ class JobTarget(msrest.serialization.Model): """ _validation = { - 'type': {'required': True}, + "type": {"required": True}, } _attribute_map = { - 'membership_type': {'key': 'membershipType', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'server_name': {'key': 'serverName', 'type': 'str'}, - 'database_name': {'key': 'databaseName', 'type': 'str'}, - 'elastic_pool_name': {'key': 'elasticPoolName', 'type': 'str'}, - 'shard_map_name': {'key': 'shardMapName', 'type': 'str'}, - 'refresh_credential': {'key': 'refreshCredential', 'type': 'str'}, + "membership_type": {"key": "membershipType", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "server_name": {"key": "serverName", "type": "str"}, + "database_name": {"key": "databaseName", "type": "str"}, + "elastic_pool_name": {"key": "elasticPoolName", "type": "str"}, + "shard_map_name": {"key": "shardMapName", "type": "str"}, + "refresh_credential": {"key": "refreshCredential", "type": "str"}, } def __init__( self, *, type: Union[str, "_models.JobTargetType"], - membership_type: Optional[Union[str, "_models.JobTargetGroupMembershipType"]] = "Include", + membership_type: Union[str, "_models.JobTargetGroupMembershipType"] = "Include", server_name: Optional[str] = None, database_name: Optional[str] = None, elastic_pool_name: Optional[str] = None, @@ -8096,10 +7765,10 @@ def __init__( ): """ :keyword membership_type: Whether the target is included or excluded from the group. Known - values are: "Include", "Exclude". Default value: "Include". + values are: "Include" and "Exclude". :paramtype membership_type: str or ~azure.mgmt.sql.models.JobTargetGroupMembershipType - :keyword type: Required. The target type. Known values are: "TargetGroup", "SqlDatabase", - "SqlElasticPool", "SqlShardMap", "SqlServer". + :keyword type: The target type. Required. Known values are: "TargetGroup", "SqlDatabase", + "SqlElasticPool", "SqlShardMap", and "SqlServer". :paramtype type: str or ~azure.mgmt.sql.models.JobTargetType :keyword server_name: The target server name. :paramtype server_name: str @@ -8113,7 +7782,7 @@ def __init__( execution to connect to the target and determine the list of databases inside the target. :paramtype refresh_credential: str """ - super(JobTarget, self).__init__(**kwargs) + super().__init__(**kwargs) self.membership_type = membership_type self.type = type self.server_name = server_name @@ -8139,33 +7808,28 @@ class JobTargetGroup(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'members': {'key': 'properties.members', 'type': '[JobTarget]'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "members": {"key": "properties.members", "type": "[JobTarget]"}, } - def __init__( - self, - *, - members: Optional[List["_models.JobTarget"]] = None, - **kwargs - ): + def __init__(self, *, members: Optional[List["_models.JobTarget"]] = None, **kwargs): """ :keyword members: Members of the target group. :paramtype members: list[~azure.mgmt.sql.models.JobTarget] """ - super(JobTargetGroup, self).__init__(**kwargs) + super().__init__(**kwargs) self.members = members -class JobTargetGroupListResult(msrest.serialization.Model): +class JobTargetGroupListResult(_serialization.Model): """A list of target groups. Variables are only populated by the server, and will be ignored when sending a request. @@ -8177,22 +7841,18 @@ class JobTargetGroupListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[JobTargetGroup]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[JobTargetGroup]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(JobTargetGroupListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -8211,27 +7871,23 @@ class JobVersion(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(JobVersion, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) -class JobVersionListResult(msrest.serialization.Model): +class JobVersionListResult(_serialization.Model): """A list of job versions. Variables are only populated by the server, and will be ignored when sending a request. @@ -8243,22 +7899,18 @@ class JobVersionListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[JobVersion]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[JobVersion]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(JobVersionListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -8277,43 +7929,38 @@ class LedgerDigestUploads(ProxyResource): :ivar digest_storage_endpoint: The digest storage endpoint, which must be either an Azure blob storage endpoint or an URI for Azure Confidential Ledger. :vartype digest_storage_endpoint: str - :ivar state: Specifies the state of ledger digest upload. Known values are: "Enabled", + :ivar state: Specifies the state of ledger digest upload. Known values are: "Enabled" and "Disabled". :vartype state: str or ~azure.mgmt.sql.models.LedgerDigestUploadsState """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'state': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "state": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'digest_storage_endpoint': {'key': 'properties.digestStorageEndpoint', 'type': 'str'}, - 'state': {'key': 'properties.state', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "digest_storage_endpoint": {"key": "properties.digestStorageEndpoint", "type": "str"}, + "state": {"key": "properties.state", "type": "str"}, } - def __init__( - self, - *, - digest_storage_endpoint: Optional[str] = None, - **kwargs - ): + def __init__(self, *, digest_storage_endpoint: Optional[str] = None, **kwargs): """ :keyword digest_storage_endpoint: The digest storage endpoint, which must be either an Azure blob storage endpoint or an URI for Azure Confidential Ledger. :paramtype digest_storage_endpoint: str """ - super(LedgerDigestUploads, self).__init__(**kwargs) + super().__init__(**kwargs) self.digest_storage_endpoint = digest_storage_endpoint self.state = None -class LedgerDigestUploadsListResult(msrest.serialization.Model): +class LedgerDigestUploadsListResult(_serialization.Model): """A list of ledger digest upload settings. Variables are only populated by the server, and will be ignored when sending a request. @@ -8325,27 +7972,23 @@ class LedgerDigestUploadsListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[LedgerDigestUploads]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[LedgerDigestUploads]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(LedgerDigestUploadsListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class LicenseTypeCapability(msrest.serialization.Model): +class LicenseTypeCapability(_serialization.Model): """The license type capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -8353,40 +7996,35 @@ class LicenseTypeCapability(msrest.serialization.Model): :ivar name: License type identifier. :vartype name: str :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'name': {'readonly': True}, - 'status': {'readonly': True}, + "name": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "name": {"key": "name", "type": "str"}, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(LicenseTypeCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.name = None self.status = None self.reason = reason -class LocationCapabilities(msrest.serialization.Model): +class LocationCapabilities(_serialization.Model): """The location capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -8399,38 +8037,36 @@ class LocationCapabilities(msrest.serialization.Model): :vartype supported_managed_instance_versions: list[~azure.mgmt.sql.models.ManagedInstanceVersionCapability] :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'name': {'readonly': True}, - 'supported_server_versions': {'readonly': True}, - 'supported_managed_instance_versions': {'readonly': True}, - 'status': {'readonly': True}, + "name": {"readonly": True}, + "supported_server_versions": {"readonly": True}, + "supported_managed_instance_versions": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'supported_server_versions': {'key': 'supportedServerVersions', 'type': '[ServerVersionCapability]'}, - 'supported_managed_instance_versions': {'key': 'supportedManagedInstanceVersions', 'type': '[ManagedInstanceVersionCapability]'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "name": {"key": "name", "type": "str"}, + "supported_server_versions": {"key": "supportedServerVersions", "type": "[ServerVersionCapability]"}, + "supported_managed_instance_versions": { + "key": "supportedManagedInstanceVersions", + "type": "[ManagedInstanceVersionCapability]", + }, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(LocationCapabilities, self).__init__(**kwargs) + super().__init__(**kwargs) self.name = None self.supported_server_versions = None self.supported_managed_instance_versions = None @@ -8450,39 +8086,34 @@ class LogicalDatabaseTransparentDataEncryption(ProxyResource): :ivar type: Resource type. :vartype type: str :ivar state: Specifies the state of the transparent data encryption. Known values are: - "Enabled", "Disabled". + "Enabled" and "Disabled". :vartype state: str or ~azure.mgmt.sql.models.TransparentDataEncryptionState """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'state': {'key': 'properties.state', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "state": {"key": "properties.state", "type": "str"}, } - def __init__( - self, - *, - state: Optional[Union[str, "_models.TransparentDataEncryptionState"]] = None, - **kwargs - ): + def __init__(self, *, state: Optional[Union[str, "_models.TransparentDataEncryptionState"]] = None, **kwargs): """ :keyword state: Specifies the state of the transparent data encryption. Known values are: - "Enabled", "Disabled". + "Enabled" and "Disabled". :paramtype state: str or ~azure.mgmt.sql.models.TransparentDataEncryptionState """ - super(LogicalDatabaseTransparentDataEncryption, self).__init__(**kwargs) + super().__init__(**kwargs) self.state = state -class LogicalDatabaseTransparentDataEncryptionListResult(msrest.serialization.Model): +class LogicalDatabaseTransparentDataEncryptionListResult(_serialization.Model): """A list of transparent data encryptions. Variables are only populated by the server, and will be ignored when sending a request. @@ -8494,27 +8125,23 @@ class LogicalDatabaseTransparentDataEncryptionListResult(msrest.serialization.Mo """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[LogicalDatabaseTransparentDataEncryption]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[LogicalDatabaseTransparentDataEncryption]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(LogicalDatabaseTransparentDataEncryptionListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class LogicalServerAdvancedThreatProtectionListResult(msrest.serialization.Model): +class LogicalServerAdvancedThreatProtectionListResult(_serialization.Model): """A list of the server's Advanced Threat Protection configurations. Variables are only populated by the server, and will be ignored when sending a request. @@ -8526,27 +8153,23 @@ class LogicalServerAdvancedThreatProtectionListResult(msrest.serialization.Model """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ServerAdvancedThreatProtection]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ServerAdvancedThreatProtection]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(LogicalServerAdvancedThreatProtectionListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class LogicalServerSecurityAlertPolicyListResult(msrest.serialization.Model): +class LogicalServerSecurityAlertPolicyListResult(_serialization.Model): """A list of the server's security alert policies. Variables are only populated by the server, and will be ignored when sending a request. @@ -8558,27 +8181,23 @@ class LogicalServerSecurityAlertPolicyListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ServerSecurityAlertPolicy]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ServerSecurityAlertPolicy]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(LogicalServerSecurityAlertPolicyListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class LogSizeCapability(msrest.serialization.Model): +class LogSizeCapability(_serialization.Model): """The log size capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -8586,32 +8205,28 @@ class LogSizeCapability(msrest.serialization.Model): :ivar limit: The log size limit (see 'unit' for the units). :vartype limit: int :ivar unit: The units that the limit is expressed in. Known values are: "Megabytes", - "Gigabytes", "Terabytes", "Petabytes", "Percent". + "Gigabytes", "Terabytes", "Petabytes", and "Percent". :vartype unit: str or ~azure.mgmt.sql.models.LogSizeUnit """ _validation = { - 'limit': {'readonly': True}, - 'unit': {'readonly': True}, + "limit": {"readonly": True}, + "unit": {"readonly": True}, } _attribute_map = { - 'limit': {'key': 'limit', 'type': 'int'}, - 'unit': {'key': 'unit', 'type': 'str'}, + "limit": {"key": "limit", "type": "int"}, + "unit": {"key": "unit", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(LogSizeCapability, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.limit = None self.unit = None -class LongTermRetentionBackup(ProxyResource): +class LongTermRetentionBackup(ProxyResource): # pylint: disable=too-many-instance-attributes """A long term retention backup. Variables are only populated by the server, and will be ignored when sending a request. @@ -8635,39 +8250,39 @@ class LongTermRetentionBackup(ProxyResource): :ivar backup_expiration_time: The time the long term retention backup will expire. :vartype backup_expiration_time: ~datetime.datetime :ivar backup_storage_redundancy: The storage redundancy type of the backup. Known values are: - "Geo", "Local", "Zone", "GeoZone". + "Geo", "Local", "Zone", and "GeoZone". :vartype backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy :ivar requested_backup_storage_redundancy: The storage redundancy type of the backup. Known - values are: "Geo", "Local", "Zone", "GeoZone". + values are: "Geo", "Local", "Zone", and "GeoZone". :vartype requested_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'server_name': {'readonly': True}, - 'server_create_time': {'readonly': True}, - 'database_name': {'readonly': True}, - 'database_deletion_time': {'readonly': True}, - 'backup_time': {'readonly': True}, - 'backup_expiration_time': {'readonly': True}, - 'backup_storage_redundancy': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "server_name": {"readonly": True}, + "server_create_time": {"readonly": True}, + "database_name": {"readonly": True}, + "database_deletion_time": {"readonly": True}, + "backup_time": {"readonly": True}, + "backup_expiration_time": {"readonly": True}, + "backup_storage_redundancy": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'server_name': {'key': 'properties.serverName', 'type': 'str'}, - 'server_create_time': {'key': 'properties.serverCreateTime', 'type': 'iso-8601'}, - 'database_name': {'key': 'properties.databaseName', 'type': 'str'}, - 'database_deletion_time': {'key': 'properties.databaseDeletionTime', 'type': 'iso-8601'}, - 'backup_time': {'key': 'properties.backupTime', 'type': 'iso-8601'}, - 'backup_expiration_time': {'key': 'properties.backupExpirationTime', 'type': 'iso-8601'}, - 'backup_storage_redundancy': {'key': 'properties.backupStorageRedundancy', 'type': 'str'}, - 'requested_backup_storage_redundancy': {'key': 'properties.requestedBackupStorageRedundancy', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "server_name": {"key": "properties.serverName", "type": "str"}, + "server_create_time": {"key": "properties.serverCreateTime", "type": "iso-8601"}, + "database_name": {"key": "properties.databaseName", "type": "str"}, + "database_deletion_time": {"key": "properties.databaseDeletionTime", "type": "iso-8601"}, + "backup_time": {"key": "properties.backupTime", "type": "iso-8601"}, + "backup_expiration_time": {"key": "properties.backupExpirationTime", "type": "iso-8601"}, + "backup_storage_redundancy": {"key": "properties.backupStorageRedundancy", "type": "str"}, + "requested_backup_storage_redundancy": {"key": "properties.requestedBackupStorageRedundancy", "type": "str"}, } def __init__( @@ -8678,11 +8293,11 @@ def __init__( ): """ :keyword requested_backup_storage_redundancy: The storage redundancy type of the backup. Known - values are: "Geo", "Local", "Zone", "GeoZone". + values are: "Geo", "Local", "Zone", and "GeoZone". :paramtype requested_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy """ - super(LongTermRetentionBackup, self).__init__(**kwargs) + super().__init__(**kwargs) self.server_name = None self.server_create_time = None self.database_name = None @@ -8693,7 +8308,7 @@ def __init__( self.requested_backup_storage_redundancy = requested_backup_storage_redundancy -class LongTermRetentionBackupListResult(msrest.serialization.Model): +class LongTermRetentionBackupListResult(_serialization.Model): """A list of long term retention backups. Variables are only populated by the server, and will be ignored when sending a request. @@ -8705,22 +8320,18 @@ class LongTermRetentionBackupListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[LongTermRetentionBackup]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[LongTermRetentionBackup]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(LongTermRetentionBackupListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -8745,7 +8356,7 @@ class LongTermRetentionBackupOperationResult(ProxyResource): :ivar to_backup_resource_id: Target backup resource id. :vartype to_backup_resource_id: str :ivar target_backup_storage_redundancy: The storage redundancy type of the copied backup. Known - values are: "Geo", "Local", "Zone", "GeoZone". + values are: "Geo", "Local", "Zone", and "GeoZone". :vartype target_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy :ivar status: Operation status. @@ -8755,38 +8366,34 @@ class LongTermRetentionBackupOperationResult(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'request_id': {'readonly': True}, - 'operation_type': {'readonly': True}, - 'from_backup_resource_id': {'readonly': True}, - 'to_backup_resource_id': {'readonly': True}, - 'target_backup_storage_redundancy': {'readonly': True}, - 'status': {'readonly': True}, - 'message': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "request_id": {"readonly": True}, + "operation_type": {"readonly": True}, + "from_backup_resource_id": {"readonly": True}, + "to_backup_resource_id": {"readonly": True}, + "target_backup_storage_redundancy": {"readonly": True}, + "status": {"readonly": True}, + "message": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'request_id': {'key': 'properties.requestId', 'type': 'str'}, - 'operation_type': {'key': 'properties.operationType', 'type': 'str'}, - 'from_backup_resource_id': {'key': 'properties.fromBackupResourceId', 'type': 'str'}, - 'to_backup_resource_id': {'key': 'properties.toBackupResourceId', 'type': 'str'}, - 'target_backup_storage_redundancy': {'key': 'properties.targetBackupStorageRedundancy', 'type': 'str'}, - 'status': {'key': 'properties.status', 'type': 'str'}, - 'message': {'key': 'properties.message', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "request_id": {"key": "properties.requestId", "type": "str"}, + "operation_type": {"key": "properties.operationType", "type": "str"}, + "from_backup_resource_id": {"key": "properties.fromBackupResourceId", "type": "str"}, + "to_backup_resource_id": {"key": "properties.toBackupResourceId", "type": "str"}, + "target_backup_storage_redundancy": {"key": "properties.targetBackupStorageRedundancy", "type": "str"}, + "status": {"key": "properties.status", "type": "str"}, + "message": {"key": "properties.message", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(LongTermRetentionBackupOperationResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.request_id = None self.operation_type = None self.from_backup_resource_id = None @@ -8818,19 +8425,19 @@ class LongTermRetentionPolicy(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'weekly_retention': {'key': 'properties.weeklyRetention', 'type': 'str'}, - 'monthly_retention': {'key': 'properties.monthlyRetention', 'type': 'str'}, - 'yearly_retention': {'key': 'properties.yearlyRetention', 'type': 'str'}, - 'week_of_year': {'key': 'properties.weekOfYear', 'type': 'int'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "weekly_retention": {"key": "properties.weeklyRetention", "type": "str"}, + "monthly_retention": {"key": "properties.monthlyRetention", "type": "str"}, + "yearly_retention": {"key": "properties.yearlyRetention", "type": "str"}, + "week_of_year": {"key": "properties.weekOfYear", "type": "int"}, } def __init__( @@ -8853,14 +8460,14 @@ def __init__( :keyword week_of_year: The week of year to take the yearly backup in an ISO 8601 format. :paramtype week_of_year: int """ - super(LongTermRetentionPolicy, self).__init__(**kwargs) + super().__init__(**kwargs) self.weekly_retention = weekly_retention self.monthly_retention = monthly_retention self.yearly_retention = yearly_retention self.week_of_year = week_of_year -class LongTermRetentionPolicyListResult(msrest.serialization.Model): +class LongTermRetentionPolicyListResult(_serialization.Model): """A list of long term retention policies. Variables are only populated by the server, and will be ignored when sending a request. @@ -8872,27 +8479,23 @@ class LongTermRetentionPolicyListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[LongTermRetentionPolicy]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[LongTermRetentionPolicy]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(LongTermRetentionPolicyListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class MaintenanceConfigurationCapability(msrest.serialization.Model): +class MaintenanceConfigurationCapability(_serialization.Model): """The maintenance configuration capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -8903,36 +8506,31 @@ class MaintenanceConfigurationCapability(msrest.serialization.Model): configuration. :vartype zone_redundant: bool :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'name': {'readonly': True}, - 'zone_redundant': {'readonly': True}, - 'status': {'readonly': True}, + "name": {"readonly": True}, + "zone_redundant": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'zone_redundant': {'key': 'zoneRedundant', 'type': 'bool'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "name": {"key": "name", "type": "str"}, + "zone_redundant": {"key": "zoneRedundant", "type": "bool"}, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(MaintenanceConfigurationCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.name = None self.zone_redundant = None self.status = None @@ -8969,22 +8567,28 @@ class MaintenanceWindowOptions(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'is_enabled': {'key': 'properties.isEnabled', 'type': 'bool'}, - 'maintenance_window_cycles': {'key': 'properties.maintenanceWindowCycles', 'type': '[MaintenanceWindowTimeRange]'}, - 'min_duration_in_minutes': {'key': 'properties.minDurationInMinutes', 'type': 'int'}, - 'default_duration_in_minutes': {'key': 'properties.defaultDurationInMinutes', 'type': 'int'}, - 'min_cycles': {'key': 'properties.minCycles', 'type': 'int'}, - 'time_granularity_in_minutes': {'key': 'properties.timeGranularityInMinutes', 'type': 'int'}, - 'allow_multiple_maintenance_windows_per_cycle': {'key': 'properties.allowMultipleMaintenanceWindowsPerCycle', 'type': 'bool'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "is_enabled": {"key": "properties.isEnabled", "type": "bool"}, + "maintenance_window_cycles": { + "key": "properties.maintenanceWindowCycles", + "type": "[MaintenanceWindowTimeRange]", + }, + "min_duration_in_minutes": {"key": "properties.minDurationInMinutes", "type": "int"}, + "default_duration_in_minutes": {"key": "properties.defaultDurationInMinutes", "type": "int"}, + "min_cycles": {"key": "properties.minCycles", "type": "int"}, + "time_granularity_in_minutes": {"key": "properties.timeGranularityInMinutes", "type": "int"}, + "allow_multiple_maintenance_windows_per_cycle": { + "key": "properties.allowMultipleMaintenanceWindowsPerCycle", + "type": "bool", + }, } def __init__( @@ -9017,7 +8621,7 @@ def __init__( windows per cycle. :paramtype allow_multiple_maintenance_windows_per_cycle: bool """ - super(MaintenanceWindowOptions, self).__init__(**kwargs) + super().__init__(**kwargs) self.is_enabled = is_enabled self.maintenance_window_cycles = maintenance_window_cycles self.min_duration_in_minutes = min_duration_in_minutes @@ -9043,37 +8647,32 @@ class MaintenanceWindows(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'time_ranges': {'key': 'properties.timeRanges', 'type': '[MaintenanceWindowTimeRange]'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "time_ranges": {"key": "properties.timeRanges", "type": "[MaintenanceWindowTimeRange]"}, } - def __init__( - self, - *, - time_ranges: Optional[List["_models.MaintenanceWindowTimeRange"]] = None, - **kwargs - ): + def __init__(self, *, time_ranges: Optional[List["_models.MaintenanceWindowTimeRange"]] = None, **kwargs): """ :keyword time_ranges: :paramtype time_ranges: list[~azure.mgmt.sql.models.MaintenanceWindowTimeRange] """ - super(MaintenanceWindows, self).__init__(**kwargs) + super().__init__(**kwargs) self.time_ranges = time_ranges -class MaintenanceWindowTimeRange(msrest.serialization.Model): +class MaintenanceWindowTimeRange(_serialization.Model): """Maintenance window time range. :ivar day_of_week: Day of maintenance window. Known values are: "Sunday", "Monday", "Tuesday", - "Wednesday", "Thursday", "Friday", "Saturday". + "Wednesday", "Thursday", "Friday", and "Saturday". :vartype day_of_week: str or ~azure.mgmt.sql.models.DayOfWeek :ivar start_time: Start time minutes offset from 12am. :vartype start_time: str @@ -9082,9 +8681,9 @@ class MaintenanceWindowTimeRange(msrest.serialization.Model): """ _attribute_map = { - 'day_of_week': {'key': 'dayOfWeek', 'type': 'str'}, - 'start_time': {'key': 'startTime', 'type': 'str'}, - 'duration': {'key': 'duration', 'type': 'str'}, + "day_of_week": {"key": "dayOfWeek", "type": "str"}, + "start_time": {"key": "startTime", "type": "str"}, + "duration": {"key": "duration", "type": "str"}, } def __init__( @@ -9097,14 +8696,14 @@ def __init__( ): """ :keyword day_of_week: Day of maintenance window. Known values are: "Sunday", "Monday", - "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday". + "Tuesday", "Wednesday", "Thursday", "Friday", and "Saturday". :paramtype day_of_week: str or ~azure.mgmt.sql.models.DayOfWeek :keyword start_time: Start time minutes offset from 12am. :paramtype start_time: str :keyword duration: Duration of maintenance window in minutes. :paramtype duration: str """ - super(MaintenanceWindowTimeRange, self).__init__(**kwargs) + super().__init__(**kwargs) self.day_of_week = day_of_week self.start_time = start_time self.duration = duration @@ -9127,34 +8726,29 @@ class ManagedBackupShortTermRetentionPolicy(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'retention_days': {'key': 'properties.retentionDays', 'type': 'int'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "retention_days": {"key": "properties.retentionDays", "type": "int"}, } - def __init__( - self, - *, - retention_days: Optional[int] = None, - **kwargs - ): + def __init__(self, *, retention_days: Optional[int] = None, **kwargs): """ :keyword retention_days: The backup retention period in days. This is how many days Point-in-Time Restore will be supported. :paramtype retention_days: int """ - super(ManagedBackupShortTermRetentionPolicy, self).__init__(**kwargs) + super().__init__(**kwargs) self.retention_days = retention_days -class ManagedBackupShortTermRetentionPolicyListResult(msrest.serialization.Model): +class ManagedBackupShortTermRetentionPolicyListResult(_serialization.Model): """A list of short term retention policies. Variables are only populated by the server, and will be ignored when sending a request. @@ -9166,27 +8760,23 @@ class ManagedBackupShortTermRetentionPolicyListResult(msrest.serialization.Model """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ManagedBackupShortTermRetentionPolicy]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ManagedBackupShortTermRetentionPolicy]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedBackupShortTermRetentionPolicyListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ManagedDatabase(TrackedResource): +class ManagedDatabase(TrackedResource): # pylint: disable=too-many-instance-attributes """A managed database resource. Variables are only populated by the server, and will be ignored when sending a request. @@ -9199,14 +8789,14 @@ class ManagedDatabase(TrackedResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar location: Required. Resource location. + :ivar location: Resource location. Required. :vartype location: str - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar collation: Collation of the managed database. :vartype collation: str :ivar status: Status of the database. Known values are: "Online", "Offline", "Shutdown", - "Creating", "Inaccessible", "Restoring", "Updating". + "Creating", "Inaccessible", "Restoring", and "Updating". :vartype status: str or ~azure.mgmt.sql.models.ManagedDatabaseStatus :ivar creation_date: Creation date of the database. :vartype creation_date: ~datetime.datetime @@ -9219,7 +8809,7 @@ class ManagedDatabase(TrackedResource): :ivar default_secondary_location: Geo paired region. :vartype default_secondary_location: str :ivar catalog_collation: Collation of the metadata catalog. Known values are: - "DATABASE_DEFAULT", "SQL_Latin1_General_CP1_CI_AS". + "DATABASE_DEFAULT" and "SQL_Latin1_General_CP1_CI_AS". :vartype catalog_collation: str or ~azure.mgmt.sql.models.CatalogCollationType :ivar create_mode: Managed database create mode. PointInTimeRestore: Create a database by restoring a point in time backup of an existing database. SourceDatabaseName, @@ -9229,7 +8819,7 @@ class ManagedDatabase(TrackedResource): geo-replicated backup. RecoverableDatabaseId must be specified as the recoverable database resource ID to restore. RestoreLongTermRetentionBackup: Create a database by restoring from a long term retention backup (longTermRetentionBackupResourceId required). Known values are: - "Default", "RestoreExternalBackup", "PointInTimeRestore", "Recovery", + "Default", "RestoreExternalBackup", "PointInTimeRestore", "Recovery", and "RestoreLongTermRetentionBackup". :vartype create_mode: str or ~azure.mgmt.sql.models.ManagedDatabaseCreateMode :ivar storage_container_uri: Conditional. If createMode is RestoreExternalBackup, this value is @@ -9241,8 +8831,14 @@ class ManagedDatabase(TrackedResource): :ivar restorable_dropped_database_id: The restorable dropped database resource id to restore when creating this database. :vartype restorable_dropped_database_id: str - :ivar storage_container_sas_token: Conditional. If createMode is RestoreExternalBackup, this - value is required. Specifies the storage container sas token. + :ivar storage_container_identity: Conditional. If createMode is RestoreExternalBackup, this + value is used. Specifies the identity used for storage container authentication. Can be + 'SharedAccessSignature' or 'ManagedIdentity'; if not specified 'SharedAccessSignature' is + assumed. + :vartype storage_container_identity: str + :ivar storage_container_sas_token: Conditional. If createMode is RestoreExternalBackup and + storageContainerIdentity is not ManagedIdentity, this value is required. Specifies the storage + container sas token. :vartype storage_container_sas_token: str :ivar failover_group_id: Instance Failover Group resource identifier that this managed database belongs to. @@ -9260,40 +8856,44 @@ class ManagedDatabase(TrackedResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'location': {'required': True}, - 'status': {'readonly': True}, - 'creation_date': {'readonly': True}, - 'earliest_restore_point': {'readonly': True}, - 'default_secondary_location': {'readonly': True}, - 'failover_group_id': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'tags': {'key': 'tags', 'type': '{str}'}, - 'collation': {'key': 'properties.collation', 'type': 'str'}, - 'status': {'key': 'properties.status', 'type': 'str'}, - 'creation_date': {'key': 'properties.creationDate', 'type': 'iso-8601'}, - 'earliest_restore_point': {'key': 'properties.earliestRestorePoint', 'type': 'iso-8601'}, - 'restore_point_in_time': {'key': 'properties.restorePointInTime', 'type': 'iso-8601'}, - 'default_secondary_location': {'key': 'properties.defaultSecondaryLocation', 'type': 'str'}, - 'catalog_collation': {'key': 'properties.catalogCollation', 'type': 'str'}, - 'create_mode': {'key': 'properties.createMode', 'type': 'str'}, - 'storage_container_uri': {'key': 'properties.storageContainerUri', 'type': 'str'}, - 'source_database_id': {'key': 'properties.sourceDatabaseId', 'type': 'str'}, - 'restorable_dropped_database_id': {'key': 'properties.restorableDroppedDatabaseId', 'type': 'str'}, - 'storage_container_sas_token': {'key': 'properties.storageContainerSasToken', 'type': 'str'}, - 'failover_group_id': {'key': 'properties.failoverGroupId', 'type': 'str'}, - 'recoverable_database_id': {'key': 'properties.recoverableDatabaseId', 'type': 'str'}, - 'long_term_retention_backup_resource_id': {'key': 'properties.longTermRetentionBackupResourceId', 'type': 'str'}, - 'auto_complete_restore': {'key': 'properties.autoCompleteRestore', 'type': 'bool'}, - 'last_backup_name': {'key': 'properties.lastBackupName', 'type': 'str'}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "location": {"required": True}, + "status": {"readonly": True}, + "creation_date": {"readonly": True}, + "earliest_restore_point": {"readonly": True}, + "default_secondary_location": {"readonly": True}, + "failover_group_id": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "tags": {"key": "tags", "type": "{str}"}, + "collation": {"key": "properties.collation", "type": "str"}, + "status": {"key": "properties.status", "type": "str"}, + "creation_date": {"key": "properties.creationDate", "type": "iso-8601"}, + "earliest_restore_point": {"key": "properties.earliestRestorePoint", "type": "iso-8601"}, + "restore_point_in_time": {"key": "properties.restorePointInTime", "type": "iso-8601"}, + "default_secondary_location": {"key": "properties.defaultSecondaryLocation", "type": "str"}, + "catalog_collation": {"key": "properties.catalogCollation", "type": "str"}, + "create_mode": {"key": "properties.createMode", "type": "str"}, + "storage_container_uri": {"key": "properties.storageContainerUri", "type": "str"}, + "source_database_id": {"key": "properties.sourceDatabaseId", "type": "str"}, + "restorable_dropped_database_id": {"key": "properties.restorableDroppedDatabaseId", "type": "str"}, + "storage_container_identity": {"key": "properties.storageContainerIdentity", "type": "str"}, + "storage_container_sas_token": {"key": "properties.storageContainerSasToken", "type": "str"}, + "failover_group_id": {"key": "properties.failoverGroupId", "type": "str"}, + "recoverable_database_id": {"key": "properties.recoverableDatabaseId", "type": "str"}, + "long_term_retention_backup_resource_id": { + "key": "properties.longTermRetentionBackupResourceId", + "type": "str", + }, + "auto_complete_restore": {"key": "properties.autoCompleteRestore", "type": "bool"}, + "last_backup_name": {"key": "properties.lastBackupName", "type": "str"}, } def __init__( @@ -9308,6 +8908,7 @@ def __init__( storage_container_uri: Optional[str] = None, source_database_id: Optional[str] = None, restorable_dropped_database_id: Optional[str] = None, + storage_container_identity: Optional[str] = None, storage_container_sas_token: Optional[str] = None, recoverable_database_id: Optional[str] = None, long_term_retention_backup_resource_id: Optional[str] = None, @@ -9316,9 +8917,9 @@ def __init__( **kwargs ): """ - :keyword location: Required. Resource location. + :keyword location: Resource location. Required. :paramtype location: str - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] :keyword collation: Collation of the managed database. :paramtype collation: str @@ -9327,7 +8928,7 @@ def __init__( restored to create the new database. :paramtype restore_point_in_time: ~datetime.datetime :keyword catalog_collation: Collation of the metadata catalog. Known values are: - "DATABASE_DEFAULT", "SQL_Latin1_General_CP1_CI_AS". + "DATABASE_DEFAULT" and "SQL_Latin1_General_CP1_CI_AS". :paramtype catalog_collation: str or ~azure.mgmt.sql.models.CatalogCollationType :keyword create_mode: Managed database create mode. PointInTimeRestore: Create a database by restoring a point in time backup of an existing database. SourceDatabaseName, @@ -9337,7 +8938,7 @@ def __init__( geo-replicated backup. RecoverableDatabaseId must be specified as the recoverable database resource ID to restore. RestoreLongTermRetentionBackup: Create a database by restoring from a long term retention backup (longTermRetentionBackupResourceId required). Known values are: - "Default", "RestoreExternalBackup", "PointInTimeRestore", "Recovery", + "Default", "RestoreExternalBackup", "PointInTimeRestore", "Recovery", and "RestoreLongTermRetentionBackup". :paramtype create_mode: str or ~azure.mgmt.sql.models.ManagedDatabaseCreateMode :keyword storage_container_uri: Conditional. If createMode is RestoreExternalBackup, this value @@ -9350,8 +8951,14 @@ def __init__( :keyword restorable_dropped_database_id: The restorable dropped database resource id to restore when creating this database. :paramtype restorable_dropped_database_id: str - :keyword storage_container_sas_token: Conditional. If createMode is RestoreExternalBackup, this - value is required. Specifies the storage container sas token. + :keyword storage_container_identity: Conditional. If createMode is RestoreExternalBackup, this + value is used. Specifies the identity used for storage container authentication. Can be + 'SharedAccessSignature' or 'ManagedIdentity'; if not specified 'SharedAccessSignature' is + assumed. + :paramtype storage_container_identity: str + :keyword storage_container_sas_token: Conditional. If createMode is RestoreExternalBackup and + storageContainerIdentity is not ManagedIdentity, this value is required. Specifies the storage + container sas token. :paramtype storage_container_sas_token: str :keyword recoverable_database_id: The resource identifier of the recoverable database associated with create operation of this database. @@ -9364,7 +8971,7 @@ def __init__( :keyword last_backup_name: Last backup file name for restore of this managed database. :paramtype last_backup_name: str """ - super(ManagedDatabase, self).__init__(location=location, tags=tags, **kwargs) + super().__init__(location=location, tags=tags, **kwargs) self.collation = collation self.status = None self.creation_date = None @@ -9376,6 +8983,7 @@ def __init__( self.storage_container_uri = storage_container_uri self.source_database_id = source_database_id self.restorable_dropped_database_id = restorable_dropped_database_id + self.storage_container_identity = storage_container_identity self.storage_container_sas_token = storage_container_sas_token self.failover_group_id = None self.recoverable_database_id = recoverable_database_id @@ -9384,7 +8992,86 @@ def __init__( self.last_backup_name = last_backup_name -class ManagedDatabaseListResult(msrest.serialization.Model): +class ManagedDatabaseAdvancedThreatProtection(ProxyResource): + """A managed database Advanced Threat Protection. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Resource ID. + :vartype id: str + :ivar name: Resource name. + :vartype name: str + :ivar type: Resource type. + :vartype type: str + :ivar system_data: SystemData of AdvancedThreatProtectionResource. + :vartype system_data: ~azure.mgmt.sql.models.SystemData + :ivar state: Specifies the state of the Advanced Threat Protection, whether it is enabled or + disabled or a state has not been applied yet on the specific database or server. Known values + are: "New", "Enabled", and "Disabled". + :vartype state: str or ~azure.mgmt.sql.models.AdvancedThreatProtectionState + :ivar creation_time: Specifies the UTC creation time of the policy. + :vartype creation_time: ~datetime.datetime + """ + + _validation = { + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "system_data": {"readonly": True}, + "creation_time": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "system_data": {"key": "systemData", "type": "SystemData"}, + "state": {"key": "properties.state", "type": "str"}, + "creation_time": {"key": "properties.creationTime", "type": "iso-8601"}, + } + + def __init__(self, *, state: Optional[Union[str, "_models.AdvancedThreatProtectionState"]] = None, **kwargs): + """ + :keyword state: Specifies the state of the Advanced Threat Protection, whether it is enabled or + disabled or a state has not been applied yet on the specific database or server. Known values + are: "New", "Enabled", and "Disabled". + :paramtype state: str or ~azure.mgmt.sql.models.AdvancedThreatProtectionState + """ + super().__init__(**kwargs) + self.system_data = None + self.state = state + self.creation_time = None + + +class ManagedDatabaseAdvancedThreatProtectionListResult(_serialization.Model): + """A list of the managed database's Advanced Threat Protection settings. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: Array of results. + :vartype value: list[~azure.mgmt.sql.models.ManagedDatabaseAdvancedThreatProtection] + :ivar next_link: Link to retrieve next page of results. + :vartype next_link: str + """ + + _validation = { + "value": {"readonly": True}, + "next_link": {"readonly": True}, + } + + _attribute_map = { + "value": {"key": "value", "type": "[ManagedDatabaseAdvancedThreatProtection]"}, + "next_link": {"key": "nextLink", "type": "str"}, + } + + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) + self.value = None + self.next_link = None + + +class ManagedDatabaseListResult(_serialization.Model): """A list of managed databases. Variables are only populated by the server, and will be ignored when sending a request. @@ -9396,27 +9083,97 @@ class ManagedDatabaseListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ManagedDatabase]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ManagedDatabase]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedDatabaseListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ManagedDatabaseRestoreDetailsResult(ProxyResource): +class ManagedDatabaseMoveDefinition(_serialization.Model): + """Contains the information necessary to perform a managed database move. + + All required parameters must be populated in order to send to Azure. + + :ivar destination_managed_database_id: The destination managed database ID. Required. + :vartype destination_managed_database_id: str + """ + + _validation = { + "destination_managed_database_id": {"required": True}, + } + + _attribute_map = { + "destination_managed_database_id": {"key": "destinationManagedDatabaseId", "type": "str"}, + } + + def __init__(self, *, destination_managed_database_id: str, **kwargs): + """ + :keyword destination_managed_database_id: The destination managed database ID. Required. + :paramtype destination_managed_database_id: str + """ + super().__init__(**kwargs) + self.destination_managed_database_id = destination_managed_database_id + + +class ManagedDatabaseRestoreDetailsBackupSetProperties(_serialization.Model): + """The managed database's restore details backup set properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar status: Backup set status. + :vartype status: str + :ivar first_stripe_name: First stripe name. + :vartype first_stripe_name: str + :ivar number_of_stripes: Number of stripes. + :vartype number_of_stripes: int + :ivar backup_size_mb: Backup size. + :vartype backup_size_mb: int + :ivar restore_started_timestamp_utc: Last restored file time. + :vartype restore_started_timestamp_utc: ~datetime.datetime + :ivar restore_finished_timestamp_utc: Last restored file time. + :vartype restore_finished_timestamp_utc: ~datetime.datetime + """ + + _validation = { + "status": {"readonly": True}, + "first_stripe_name": {"readonly": True}, + "number_of_stripes": {"readonly": True}, + "backup_size_mb": {"readonly": True}, + "restore_started_timestamp_utc": {"readonly": True}, + "restore_finished_timestamp_utc": {"readonly": True}, + } + + _attribute_map = { + "status": {"key": "status", "type": "str"}, + "first_stripe_name": {"key": "firstStripeName", "type": "str"}, + "number_of_stripes": {"key": "numberOfStripes", "type": "int"}, + "backup_size_mb": {"key": "backupSizeMB", "type": "int"}, + "restore_started_timestamp_utc": {"key": "restoreStartedTimestampUtc", "type": "iso-8601"}, + "restore_finished_timestamp_utc": {"key": "restoreFinishedTimestampUtc", "type": "iso-8601"}, + } + + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) + self.status = None + self.first_stripe_name = None + self.number_of_stripes = None + self.backup_size_mb = None + self.restore_started_timestamp_utc = None + self.restore_finished_timestamp_utc = None + + +class ManagedDatabaseRestoreDetailsResult(ProxyResource): # pylint: disable=too-many-instance-attributes """A managed database restore details. Variables are only populated by the server, and will be ignored when sending a request. @@ -9427,80 +9184,175 @@ class ManagedDatabaseRestoreDetailsResult(ProxyResource): :vartype name: str :ivar type: Resource type. :vartype type: str + :ivar type_properties_type: Restore type. + :vartype type_properties_type: str :ivar status: Restore status. :vartype status: str - :ivar current_restoring_file_name: Current restoring file name. - :vartype current_restoring_file_name: str + :ivar block_reason: The reason why restore is in Blocked state. + :vartype block_reason: str + :ivar last_uploaded_file_name: Last uploaded file name. + :vartype last_uploaded_file_name: str + :ivar last_uploaded_file_time: Last uploaded file time. + :vartype last_uploaded_file_time: ~datetime.datetime :ivar last_restored_file_name: Last restored file name. :vartype last_restored_file_name: str :ivar last_restored_file_time: Last restored file time. :vartype last_restored_file_time: ~datetime.datetime :ivar percent_completed: Percent completed. - :vartype percent_completed: float - :ivar unrestorable_files: List of unrestorable files. - :vartype unrestorable_files: list[str] + :vartype percent_completed: int + :ivar current_restored_size_mb: Current restored size MB. + :vartype current_restored_size_mb: int + :ivar current_restore_plan_size_mb: Current restore plan size MB. + :vartype current_restore_plan_size_mb: int + :ivar current_backup_type: Current backup type. + :vartype current_backup_type: str + :ivar current_restoring_file_name: Current restoring file name. + :vartype current_restoring_file_name: str :ivar number_of_files_detected: Number of files detected. - :vartype number_of_files_detected: long - :ivar last_uploaded_file_name: Last uploaded file name. - :vartype last_uploaded_file_name: str - :ivar last_uploaded_file_time: Last uploaded file time. - :vartype last_uploaded_file_time: ~datetime.datetime - :ivar block_reason: The reason why restore is in Blocked state. - :vartype block_reason: str + :vartype number_of_files_detected: int + :ivar number_of_files_queued: Number of files queued. + :vartype number_of_files_queued: int + :ivar number_of_files_skipped: Number of files skipped. + :vartype number_of_files_skipped: int + :ivar number_of_files_restoring: Number of files restoring. + :vartype number_of_files_restoring: int + :ivar number_of_files_restored: Number of files restored. + :vartype number_of_files_restored: int + :ivar number_of_files_unrestorable: Number of files unrestorable. + :vartype number_of_files_unrestorable: int + :ivar full_backup_sets: Full backup sets. + :vartype full_backup_sets: + list[~azure.mgmt.sql.models.ManagedDatabaseRestoreDetailsBackupSetProperties] + :ivar diff_backup_sets: Diff backup sets. + :vartype diff_backup_sets: + list[~azure.mgmt.sql.models.ManagedDatabaseRestoreDetailsBackupSetProperties] + :ivar log_backup_sets: Log backup sets. + :vartype log_backup_sets: + list[~azure.mgmt.sql.models.ManagedDatabaseRestoreDetailsBackupSetProperties] + :ivar unrestorable_files: Unrestorable files. + :vartype unrestorable_files: + list[~azure.mgmt.sql.models.ManagedDatabaseRestoreDetailsUnrestorableFileProperties] + """ + + _validation = { + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "type_properties_type": {"readonly": True}, + "status": {"readonly": True}, + "block_reason": {"readonly": True}, + "last_uploaded_file_name": {"readonly": True}, + "last_uploaded_file_time": {"readonly": True}, + "last_restored_file_name": {"readonly": True}, + "last_restored_file_time": {"readonly": True}, + "percent_completed": {"readonly": True}, + "current_restored_size_mb": {"readonly": True}, + "current_restore_plan_size_mb": {"readonly": True}, + "current_backup_type": {"readonly": True}, + "current_restoring_file_name": {"readonly": True}, + "number_of_files_detected": {"readonly": True}, + "number_of_files_queued": {"readonly": True}, + "number_of_files_skipped": {"readonly": True}, + "number_of_files_restoring": {"readonly": True}, + "number_of_files_restored": {"readonly": True}, + "number_of_files_unrestorable": {"readonly": True}, + "full_backup_sets": {"readonly": True}, + "diff_backup_sets": {"readonly": True}, + "log_backup_sets": {"readonly": True}, + "unrestorable_files": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "type_properties_type": {"key": "properties.type", "type": "str"}, + "status": {"key": "properties.status", "type": "str"}, + "block_reason": {"key": "properties.blockReason", "type": "str"}, + "last_uploaded_file_name": {"key": "properties.lastUploadedFileName", "type": "str"}, + "last_uploaded_file_time": {"key": "properties.lastUploadedFileTime", "type": "iso-8601"}, + "last_restored_file_name": {"key": "properties.lastRestoredFileName", "type": "str"}, + "last_restored_file_time": {"key": "properties.lastRestoredFileTime", "type": "iso-8601"}, + "percent_completed": {"key": "properties.percentCompleted", "type": "int"}, + "current_restored_size_mb": {"key": "properties.currentRestoredSizeMB", "type": "int"}, + "current_restore_plan_size_mb": {"key": "properties.currentRestorePlanSizeMB", "type": "int"}, + "current_backup_type": {"key": "properties.currentBackupType", "type": "str"}, + "current_restoring_file_name": {"key": "properties.currentRestoringFileName", "type": "str"}, + "number_of_files_detected": {"key": "properties.numberOfFilesDetected", "type": "int"}, + "number_of_files_queued": {"key": "properties.numberOfFilesQueued", "type": "int"}, + "number_of_files_skipped": {"key": "properties.numberOfFilesSkipped", "type": "int"}, + "number_of_files_restoring": {"key": "properties.numberOfFilesRestoring", "type": "int"}, + "number_of_files_restored": {"key": "properties.numberOfFilesRestored", "type": "int"}, + "number_of_files_unrestorable": {"key": "properties.numberOfFilesUnrestorable", "type": "int"}, + "full_backup_sets": { + "key": "properties.fullBackupSets", + "type": "[ManagedDatabaseRestoreDetailsBackupSetProperties]", + }, + "diff_backup_sets": { + "key": "properties.diffBackupSets", + "type": "[ManagedDatabaseRestoreDetailsBackupSetProperties]", + }, + "log_backup_sets": { + "key": "properties.logBackupSets", + "type": "[ManagedDatabaseRestoreDetailsBackupSetProperties]", + }, + "unrestorable_files": { + "key": "properties.unrestorableFiles", + "type": "[ManagedDatabaseRestoreDetailsUnrestorableFileProperties]", + }, + } + + def __init__(self, **kwargs): # pylint: disable=too-many-locals + """ """ + super().__init__(**kwargs) + self.type_properties_type = None + self.status = None + self.block_reason = None + self.last_uploaded_file_name = None + self.last_uploaded_file_time = None + self.last_restored_file_name = None + self.last_restored_file_time = None + self.percent_completed = None + self.current_restored_size_mb = None + self.current_restore_plan_size_mb = None + self.current_backup_type = None + self.current_restoring_file_name = None + self.number_of_files_detected = None + self.number_of_files_queued = None + self.number_of_files_skipped = None + self.number_of_files_restoring = None + self.number_of_files_restored = None + self.number_of_files_unrestorable = None + self.full_backup_sets = None + self.diff_backup_sets = None + self.log_backup_sets = None + self.unrestorable_files = None + + +class ManagedDatabaseRestoreDetailsUnrestorableFileProperties(_serialization.Model): + """The managed database's restore details unrestorable file properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar name: File name. + :vartype name: str """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'status': {'readonly': True}, - 'current_restoring_file_name': {'readonly': True}, - 'last_restored_file_name': {'readonly': True}, - 'last_restored_file_time': {'readonly': True}, - 'percent_completed': {'readonly': True}, - 'unrestorable_files': {'readonly': True}, - 'number_of_files_detected': {'readonly': True}, - 'last_uploaded_file_name': {'readonly': True}, - 'last_uploaded_file_time': {'readonly': True}, - 'block_reason': {'readonly': True}, + "name": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'status': {'key': 'properties.status', 'type': 'str'}, - 'current_restoring_file_name': {'key': 'properties.currentRestoringFileName', 'type': 'str'}, - 'last_restored_file_name': {'key': 'properties.lastRestoredFileName', 'type': 'str'}, - 'last_restored_file_time': {'key': 'properties.lastRestoredFileTime', 'type': 'iso-8601'}, - 'percent_completed': {'key': 'properties.percentCompleted', 'type': 'float'}, - 'unrestorable_files': {'key': 'properties.unrestorableFiles', 'type': '[str]'}, - 'number_of_files_detected': {'key': 'properties.numberOfFilesDetected', 'type': 'long'}, - 'last_uploaded_file_name': {'key': 'properties.lastUploadedFileName', 'type': 'str'}, - 'last_uploaded_file_time': {'key': 'properties.lastUploadedFileTime', 'type': 'iso-8601'}, - 'block_reason': {'key': 'properties.blockReason', 'type': 'str'}, + "name": {"key": "name", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedDatabaseRestoreDetailsResult, self).__init__(**kwargs) - self.status = None - self.current_restoring_file_name = None - self.last_restored_file_name = None - self.last_restored_file_time = None - self.percent_completed = None - self.unrestorable_files = None - self.number_of_files_detected = None - self.last_uploaded_file_name = None - self.last_uploaded_file_time = None - self.block_reason = None + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) + self.name = None -class ManagedDatabaseSecurityAlertPolicy(ProxyResource): +class ManagedDatabaseSecurityAlertPolicy(ProxyResource): # pylint: disable=too-many-instance-attributes """A managed database security alert policy. Variables are only populated by the server, and will be ignored when sending a request. @@ -9512,7 +9364,7 @@ class ManagedDatabaseSecurityAlertPolicy(ProxyResource): :ivar type: Resource type. :vartype type: str :ivar state: Specifies the state of the policy, whether it is enabled or disabled or a policy - has not been applied yet on the specific database. Known values are: "New", "Enabled", + has not been applied yet on the specific database. Known values are: "New", "Enabled", and "Disabled". :vartype state: str or ~azure.mgmt.sql.models.SecurityAlertPolicyState :ivar disabled_alerts: Specifies an array of alerts that are disabled. Allowed values are: @@ -9537,24 +9389,24 @@ class ManagedDatabaseSecurityAlertPolicy(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'creation_time': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "creation_time": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'disabled_alerts': {'key': 'properties.disabledAlerts', 'type': '[str]'}, - 'email_addresses': {'key': 'properties.emailAddresses', 'type': '[str]'}, - 'email_account_admins': {'key': 'properties.emailAccountAdmins', 'type': 'bool'}, - 'storage_endpoint': {'key': 'properties.storageEndpoint', 'type': 'str'}, - 'storage_account_access_key': {'key': 'properties.storageAccountAccessKey', 'type': 'str'}, - 'retention_days': {'key': 'properties.retentionDays', 'type': 'int'}, - 'creation_time': {'key': 'properties.creationTime', 'type': 'iso-8601'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "state": {"key": "properties.state", "type": "str"}, + "disabled_alerts": {"key": "properties.disabledAlerts", "type": "[str]"}, + "email_addresses": {"key": "properties.emailAddresses", "type": "[str]"}, + "email_account_admins": {"key": "properties.emailAccountAdmins", "type": "bool"}, + "storage_endpoint": {"key": "properties.storageEndpoint", "type": "str"}, + "storage_account_access_key": {"key": "properties.storageAccountAccessKey", "type": "str"}, + "retention_days": {"key": "properties.retentionDays", "type": "int"}, + "creation_time": {"key": "properties.creationTime", "type": "iso-8601"}, } def __init__( @@ -9572,7 +9424,7 @@ def __init__( """ :keyword state: Specifies the state of the policy, whether it is enabled or disabled or a policy has not been applied yet on the specific database. Known values are: "New", "Enabled", - "Disabled". + and "Disabled". :paramtype state: str or ~azure.mgmt.sql.models.SecurityAlertPolicyState :keyword disabled_alerts: Specifies an array of alerts that are disabled. Allowed values are: Sql_Injection, Sql_Injection_Vulnerability, Access_Anomaly, Data_Exfiltration, Unsafe_Action, @@ -9593,7 +9445,7 @@ def __init__( logs. :paramtype retention_days: int """ - super(ManagedDatabaseSecurityAlertPolicy, self).__init__(**kwargs) + super().__init__(**kwargs) self.state = state self.disabled_alerts = disabled_alerts self.email_addresses = email_addresses @@ -9604,7 +9456,7 @@ def __init__( self.creation_time = None -class ManagedDatabaseSecurityAlertPolicyListResult(msrest.serialization.Model): +class ManagedDatabaseSecurityAlertPolicyListResult(_serialization.Model): """A list of the managed database's security alert policies. Variables are only populated by the server, and will be ignored when sending a request. @@ -9616,37 +9468,71 @@ class ManagedDatabaseSecurityAlertPolicyListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ManagedDatabaseSecurityAlertPolicy]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ManagedDatabaseSecurityAlertPolicy]"}, + "next_link": {"key": "nextLink", "type": "str"}, + } + + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) + self.value = None + self.next_link = None + + +class ManagedDatabaseStartMoveDefinition(_serialization.Model): + """Contains the information necessary to start a managed database move. + + All required parameters must be populated in order to send to Azure. + + :ivar destination_managed_database_id: The destination managed database ID. Required. + :vartype destination_managed_database_id: str + :ivar operation_mode: The move operation mode. Known values are: "Move" and "Copy". + :vartype operation_mode: str or ~azure.mgmt.sql.models.MoveOperationMode + """ + + _validation = { + "destination_managed_database_id": {"required": True}, + } + + _attribute_map = { + "destination_managed_database_id": {"key": "destinationManagedDatabaseId", "type": "str"}, + "operation_mode": {"key": "operationMode", "type": "str"}, } def __init__( self, + *, + destination_managed_database_id: str, + operation_mode: Union[str, "_models.MoveOperationMode"] = "Move", **kwargs ): """ + :keyword destination_managed_database_id: The destination managed database ID. Required. + :paramtype destination_managed_database_id: str + :keyword operation_mode: The move operation mode. Known values are: "Move" and "Copy". + :paramtype operation_mode: str or ~azure.mgmt.sql.models.MoveOperationMode """ - super(ManagedDatabaseSecurityAlertPolicyListResult, self).__init__(**kwargs) - self.value = None - self.next_link = None + super().__init__(**kwargs) + self.destination_managed_database_id = destination_managed_database_id + self.operation_mode = operation_mode -class ManagedDatabaseUpdate(msrest.serialization.Model): +class ManagedDatabaseUpdate(_serialization.Model): # pylint: disable=too-many-instance-attributes """An managed database update. Variables are only populated by the server, and will be ignored when sending a request. - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar collation: Collation of the managed database. :vartype collation: str :ivar status: Status of the database. Known values are: "Online", "Offline", "Shutdown", - "Creating", "Inaccessible", "Restoring", "Updating". + "Creating", "Inaccessible", "Restoring", and "Updating". :vartype status: str or ~azure.mgmt.sql.models.ManagedDatabaseStatus :ivar creation_date: Creation date of the database. :vartype creation_date: ~datetime.datetime @@ -9659,7 +9545,7 @@ class ManagedDatabaseUpdate(msrest.serialization.Model): :ivar default_secondary_location: Geo paired region. :vartype default_secondary_location: str :ivar catalog_collation: Collation of the metadata catalog. Known values are: - "DATABASE_DEFAULT", "SQL_Latin1_General_CP1_CI_AS". + "DATABASE_DEFAULT" and "SQL_Latin1_General_CP1_CI_AS". :vartype catalog_collation: str or ~azure.mgmt.sql.models.CatalogCollationType :ivar create_mode: Managed database create mode. PointInTimeRestore: Create a database by restoring a point in time backup of an existing database. SourceDatabaseName, @@ -9669,7 +9555,7 @@ class ManagedDatabaseUpdate(msrest.serialization.Model): geo-replicated backup. RecoverableDatabaseId must be specified as the recoverable database resource ID to restore. RestoreLongTermRetentionBackup: Create a database by restoring from a long term retention backup (longTermRetentionBackupResourceId required). Known values are: - "Default", "RestoreExternalBackup", "PointInTimeRestore", "Recovery", + "Default", "RestoreExternalBackup", "PointInTimeRestore", "Recovery", and "RestoreLongTermRetentionBackup". :vartype create_mode: str or ~azure.mgmt.sql.models.ManagedDatabaseCreateMode :ivar storage_container_uri: Conditional. If createMode is RestoreExternalBackup, this value is @@ -9681,8 +9567,14 @@ class ManagedDatabaseUpdate(msrest.serialization.Model): :ivar restorable_dropped_database_id: The restorable dropped database resource id to restore when creating this database. :vartype restorable_dropped_database_id: str - :ivar storage_container_sas_token: Conditional. If createMode is RestoreExternalBackup, this - value is required. Specifies the storage container sas token. + :ivar storage_container_identity: Conditional. If createMode is RestoreExternalBackup, this + value is used. Specifies the identity used for storage container authentication. Can be + 'SharedAccessSignature' or 'ManagedIdentity'; if not specified 'SharedAccessSignature' is + assumed. + :vartype storage_container_identity: str + :ivar storage_container_sas_token: Conditional. If createMode is RestoreExternalBackup and + storageContainerIdentity is not ManagedIdentity, this value is required. Specifies the storage + container sas token. :vartype storage_container_sas_token: str :ivar failover_group_id: Instance Failover Group resource identifier that this managed database belongs to. @@ -9700,32 +9592,36 @@ class ManagedDatabaseUpdate(msrest.serialization.Model): """ _validation = { - 'status': {'readonly': True}, - 'creation_date': {'readonly': True}, - 'earliest_restore_point': {'readonly': True}, - 'default_secondary_location': {'readonly': True}, - 'failover_group_id': {'readonly': True}, + "status": {"readonly": True}, + "creation_date": {"readonly": True}, + "earliest_restore_point": {"readonly": True}, + "default_secondary_location": {"readonly": True}, + "failover_group_id": {"readonly": True}, } _attribute_map = { - 'tags': {'key': 'tags', 'type': '{str}'}, - 'collation': {'key': 'properties.collation', 'type': 'str'}, - 'status': {'key': 'properties.status', 'type': 'str'}, - 'creation_date': {'key': 'properties.creationDate', 'type': 'iso-8601'}, - 'earliest_restore_point': {'key': 'properties.earliestRestorePoint', 'type': 'iso-8601'}, - 'restore_point_in_time': {'key': 'properties.restorePointInTime', 'type': 'iso-8601'}, - 'default_secondary_location': {'key': 'properties.defaultSecondaryLocation', 'type': 'str'}, - 'catalog_collation': {'key': 'properties.catalogCollation', 'type': 'str'}, - 'create_mode': {'key': 'properties.createMode', 'type': 'str'}, - 'storage_container_uri': {'key': 'properties.storageContainerUri', 'type': 'str'}, - 'source_database_id': {'key': 'properties.sourceDatabaseId', 'type': 'str'}, - 'restorable_dropped_database_id': {'key': 'properties.restorableDroppedDatabaseId', 'type': 'str'}, - 'storage_container_sas_token': {'key': 'properties.storageContainerSasToken', 'type': 'str'}, - 'failover_group_id': {'key': 'properties.failoverGroupId', 'type': 'str'}, - 'recoverable_database_id': {'key': 'properties.recoverableDatabaseId', 'type': 'str'}, - 'long_term_retention_backup_resource_id': {'key': 'properties.longTermRetentionBackupResourceId', 'type': 'str'}, - 'auto_complete_restore': {'key': 'properties.autoCompleteRestore', 'type': 'bool'}, - 'last_backup_name': {'key': 'properties.lastBackupName', 'type': 'str'}, + "tags": {"key": "tags", "type": "{str}"}, + "collation": {"key": "properties.collation", "type": "str"}, + "status": {"key": "properties.status", "type": "str"}, + "creation_date": {"key": "properties.creationDate", "type": "iso-8601"}, + "earliest_restore_point": {"key": "properties.earliestRestorePoint", "type": "iso-8601"}, + "restore_point_in_time": {"key": "properties.restorePointInTime", "type": "iso-8601"}, + "default_secondary_location": {"key": "properties.defaultSecondaryLocation", "type": "str"}, + "catalog_collation": {"key": "properties.catalogCollation", "type": "str"}, + "create_mode": {"key": "properties.createMode", "type": "str"}, + "storage_container_uri": {"key": "properties.storageContainerUri", "type": "str"}, + "source_database_id": {"key": "properties.sourceDatabaseId", "type": "str"}, + "restorable_dropped_database_id": {"key": "properties.restorableDroppedDatabaseId", "type": "str"}, + "storage_container_identity": {"key": "properties.storageContainerIdentity", "type": "str"}, + "storage_container_sas_token": {"key": "properties.storageContainerSasToken", "type": "str"}, + "failover_group_id": {"key": "properties.failoverGroupId", "type": "str"}, + "recoverable_database_id": {"key": "properties.recoverableDatabaseId", "type": "str"}, + "long_term_retention_backup_resource_id": { + "key": "properties.longTermRetentionBackupResourceId", + "type": "str", + }, + "auto_complete_restore": {"key": "properties.autoCompleteRestore", "type": "bool"}, + "last_backup_name": {"key": "properties.lastBackupName", "type": "str"}, } def __init__( @@ -9739,6 +9635,7 @@ def __init__( storage_container_uri: Optional[str] = None, source_database_id: Optional[str] = None, restorable_dropped_database_id: Optional[str] = None, + storage_container_identity: Optional[str] = None, storage_container_sas_token: Optional[str] = None, recoverable_database_id: Optional[str] = None, long_term_retention_backup_resource_id: Optional[str] = None, @@ -9747,7 +9644,7 @@ def __init__( **kwargs ): """ - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] :keyword collation: Collation of the managed database. :paramtype collation: str @@ -9756,7 +9653,7 @@ def __init__( restored to create the new database. :paramtype restore_point_in_time: ~datetime.datetime :keyword catalog_collation: Collation of the metadata catalog. Known values are: - "DATABASE_DEFAULT", "SQL_Latin1_General_CP1_CI_AS". + "DATABASE_DEFAULT" and "SQL_Latin1_General_CP1_CI_AS". :paramtype catalog_collation: str or ~azure.mgmt.sql.models.CatalogCollationType :keyword create_mode: Managed database create mode. PointInTimeRestore: Create a database by restoring a point in time backup of an existing database. SourceDatabaseName, @@ -9766,7 +9663,7 @@ def __init__( geo-replicated backup. RecoverableDatabaseId must be specified as the recoverable database resource ID to restore. RestoreLongTermRetentionBackup: Create a database by restoring from a long term retention backup (longTermRetentionBackupResourceId required). Known values are: - "Default", "RestoreExternalBackup", "PointInTimeRestore", "Recovery", + "Default", "RestoreExternalBackup", "PointInTimeRestore", "Recovery", and "RestoreLongTermRetentionBackup". :paramtype create_mode: str or ~azure.mgmt.sql.models.ManagedDatabaseCreateMode :keyword storage_container_uri: Conditional. If createMode is RestoreExternalBackup, this value @@ -9779,8 +9676,14 @@ def __init__( :keyword restorable_dropped_database_id: The restorable dropped database resource id to restore when creating this database. :paramtype restorable_dropped_database_id: str - :keyword storage_container_sas_token: Conditional. If createMode is RestoreExternalBackup, this - value is required. Specifies the storage container sas token. + :keyword storage_container_identity: Conditional. If createMode is RestoreExternalBackup, this + value is used. Specifies the identity used for storage container authentication. Can be + 'SharedAccessSignature' or 'ManagedIdentity'; if not specified 'SharedAccessSignature' is + assumed. + :paramtype storage_container_identity: str + :keyword storage_container_sas_token: Conditional. If createMode is RestoreExternalBackup and + storageContainerIdentity is not ManagedIdentity, this value is required. Specifies the storage + container sas token. :paramtype storage_container_sas_token: str :keyword recoverable_database_id: The resource identifier of the recoverable database associated with create operation of this database. @@ -9793,7 +9696,7 @@ def __init__( :keyword last_backup_name: Last backup file name for restore of this managed database. :paramtype last_backup_name: str """ - super(ManagedDatabaseUpdate, self).__init__(**kwargs) + super().__init__(**kwargs) self.tags = tags self.collation = collation self.status = None @@ -9806,6 +9709,7 @@ def __init__( self.storage_container_uri = storage_container_uri self.source_database_id = source_database_id self.restorable_dropped_database_id = restorable_dropped_database_id + self.storage_container_identity = storage_container_identity self.storage_container_sas_token = storage_container_sas_token self.failover_group_id = None self.recoverable_database_id = recoverable_database_id @@ -9814,7 +9718,7 @@ def __init__( self.last_backup_name = last_backup_name -class ManagedInstance(TrackedResource): +class ManagedInstance(TrackedResource): # pylint: disable=too-many-instance-attributes """An Azure SQL managed instance. Variables are only populated by the server, and will be ignored when sending a request. @@ -9827,9 +9731,9 @@ class ManagedInstance(TrackedResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar location: Required. Resource location. + :ivar location: Resource location. Required. :vartype location: str - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar identity: The Azure Active Directory identity of the managed instance. :vartype identity: ~azure.mgmt.sql.models.ResourceIdentity @@ -9838,16 +9742,16 @@ class ManagedInstance(TrackedResource): :vartype sku: ~azure.mgmt.sql.models.Sku :ivar provisioning_state: Known values are: "Creating", "Deleting", "Updating", "Unknown", "Succeeded", "Failed", "Accepted", "Created", "Deleted", "Unrecognized", "Running", "Canceled", - "NotSpecified", "Registering", "TimedOut". + "NotSpecified", "Registering", and "TimedOut". :vartype provisioning_state: str or ~azure.mgmt.sql.models.ManagedInstancePropertiesProvisioningState :ivar managed_instance_create_mode: Specifies the mode of database creation. - + Default: Regular instance creation. - + Restore: Creates an instance by restoring a set of backups to specific point in time. - RestorePointInTime and SourceManagedInstanceId must be specified. Known values are: "Default", - "PointInTimeRestore". + RestorePointInTime and SourceManagedInstanceId must be specified. Known values are: "Default" + and "PointInTimeRestore". :vartype managed_instance_create_mode: str or ~azure.mgmt.sql.models.ManagedServerCreateMode :ivar fully_qualified_domain_name: The fully qualified domain name of the managed instance. :vartype fully_qualified_domain_name: str @@ -9863,7 +9767,7 @@ class ManagedInstance(TrackedResource): :vartype state: str :ivar license_type: The license type. Possible values are 'LicenseIncluded' (regular price inclusive of a new SQL license) and 'BasePrice' (discounted AHB price for bringing your own SQL - licenses). Known values are: "LicenseIncluded", "BasePrice". + licenses). Known values are: "LicenseIncluded" and "BasePrice". :vartype license_type: str or ~azure.mgmt.sql.models.ManagedInstanceLicenseType :ivar v_cores: The number of vCores. Allowed values: 8, 16, 24, 32, 40, 64, 80. :vartype v_cores: int @@ -9886,7 +9790,7 @@ class ManagedInstance(TrackedResource): database that will be restored to create the new database. :vartype restore_point_in_time: ~datetime.datetime :ivar proxy_override: Connection type used for connecting to the instance. Known values are: - "Proxy", "Redirect", "Default". + "Proxy", "Redirect", and "Default". :vartype proxy_override: str or ~azure.mgmt.sql.models.ManagedInstanceProxyOverride :ivar timezone_id: Id of the timezone. Allowed values are timezones supported by Windows. Windows keeps details on supported timezones, including the id, in registry under @@ -9909,13 +9813,13 @@ class ManagedInstance(TrackedResource): :ivar current_backup_storage_redundancy: The storage account type used to store backups for this instance. The options are Local (LocallyRedundantStorage), Zone (ZoneRedundantStorage), Geo (GeoRedundantStorage) and GeoZone(GeoZoneRedundantStorage). Known values are: "Geo", - "Local", "Zone", "GeoZone". + "Local", "Zone", and "GeoZone". :vartype current_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy :ivar requested_backup_storage_redundancy: The storage account type to be used to store backups for this instance. The options are Local (LocallyRedundantStorage), Zone (ZoneRedundantStorage), Geo (GeoRedundantStorage) and GeoZone(GeoZoneRedundantStorage). Known - values are: "Geo", "Local", "Zone", "GeoZone". + values are: "Geo", "Local", "Zone", and "GeoZone". :vartype requested_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy :ivar zone_redundant: Whether or not the multi-az is enabled. @@ -9932,58 +9836,61 @@ class ManagedInstance(TrackedResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'location': {'required': True}, - 'provisioning_state': {'readonly': True}, - 'fully_qualified_domain_name': {'readonly': True}, - 'state': {'readonly': True}, - 'dns_zone': {'readonly': True}, - 'private_endpoint_connections': {'readonly': True}, - 'current_backup_storage_redundancy': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'tags': {'key': 'tags', 'type': '{str}'}, - 'identity': {'key': 'identity', 'type': 'ResourceIdentity'}, - 'sku': {'key': 'sku', 'type': 'Sku'}, - 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, - 'managed_instance_create_mode': {'key': 'properties.managedInstanceCreateMode', 'type': 'str'}, - 'fully_qualified_domain_name': {'key': 'properties.fullyQualifiedDomainName', 'type': 'str'}, - 'administrator_login': {'key': 'properties.administratorLogin', 'type': 'str'}, - 'administrator_login_password': {'key': 'properties.administratorLoginPassword', 'type': 'str'}, - 'subnet_id': {'key': 'properties.subnetId', 'type': 'str'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'license_type': {'key': 'properties.licenseType', 'type': 'str'}, - 'v_cores': {'key': 'properties.vCores', 'type': 'int'}, - 'storage_size_in_gb': {'key': 'properties.storageSizeInGB', 'type': 'int'}, - 'collation': {'key': 'properties.collation', 'type': 'str'}, - 'dns_zone': {'key': 'properties.dnsZone', 'type': 'str'}, - 'dns_zone_partner': {'key': 'properties.dnsZonePartner', 'type': 'str'}, - 'public_data_endpoint_enabled': {'key': 'properties.publicDataEndpointEnabled', 'type': 'bool'}, - 'source_managed_instance_id': {'key': 'properties.sourceManagedInstanceId', 'type': 'str'}, - 'restore_point_in_time': {'key': 'properties.restorePointInTime', 'type': 'iso-8601'}, - 'proxy_override': {'key': 'properties.proxyOverride', 'type': 'str'}, - 'timezone_id': {'key': 'properties.timezoneId', 'type': 'str'}, - 'instance_pool_id': {'key': 'properties.instancePoolId', 'type': 'str'}, - 'maintenance_configuration_id': {'key': 'properties.maintenanceConfigurationId', 'type': 'str'}, - 'private_endpoint_connections': {'key': 'properties.privateEndpointConnections', 'type': '[ManagedInstancePecProperty]'}, - 'minimal_tls_version': {'key': 'properties.minimalTlsVersion', 'type': 'str'}, - 'current_backup_storage_redundancy': {'key': 'properties.currentBackupStorageRedundancy', 'type': 'str'}, - 'requested_backup_storage_redundancy': {'key': 'properties.requestedBackupStorageRedundancy', 'type': 'str'}, - 'zone_redundant': {'key': 'properties.zoneRedundant', 'type': 'bool'}, - 'primary_user_assigned_identity_id': {'key': 'properties.primaryUserAssignedIdentityId', 'type': 'str'}, - 'key_id': {'key': 'properties.keyId', 'type': 'str'}, - 'administrators': {'key': 'properties.administrators', 'type': 'ManagedInstanceExternalAdministrator'}, - 'service_principal': {'key': 'properties.servicePrincipal', 'type': 'ServicePrincipal'}, - } - - def __init__( + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "location": {"required": True}, + "provisioning_state": {"readonly": True}, + "fully_qualified_domain_name": {"readonly": True}, + "state": {"readonly": True}, + "dns_zone": {"readonly": True}, + "private_endpoint_connections": {"readonly": True}, + "current_backup_storage_redundancy": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "tags": {"key": "tags", "type": "{str}"}, + "identity": {"key": "identity", "type": "ResourceIdentity"}, + "sku": {"key": "sku", "type": "Sku"}, + "provisioning_state": {"key": "properties.provisioningState", "type": "str"}, + "managed_instance_create_mode": {"key": "properties.managedInstanceCreateMode", "type": "str"}, + "fully_qualified_domain_name": {"key": "properties.fullyQualifiedDomainName", "type": "str"}, + "administrator_login": {"key": "properties.administratorLogin", "type": "str"}, + "administrator_login_password": {"key": "properties.administratorLoginPassword", "type": "str"}, + "subnet_id": {"key": "properties.subnetId", "type": "str"}, + "state": {"key": "properties.state", "type": "str"}, + "license_type": {"key": "properties.licenseType", "type": "str"}, + "v_cores": {"key": "properties.vCores", "type": "int"}, + "storage_size_in_gb": {"key": "properties.storageSizeInGB", "type": "int"}, + "collation": {"key": "properties.collation", "type": "str"}, + "dns_zone": {"key": "properties.dnsZone", "type": "str"}, + "dns_zone_partner": {"key": "properties.dnsZonePartner", "type": "str"}, + "public_data_endpoint_enabled": {"key": "properties.publicDataEndpointEnabled", "type": "bool"}, + "source_managed_instance_id": {"key": "properties.sourceManagedInstanceId", "type": "str"}, + "restore_point_in_time": {"key": "properties.restorePointInTime", "type": "iso-8601"}, + "proxy_override": {"key": "properties.proxyOverride", "type": "str"}, + "timezone_id": {"key": "properties.timezoneId", "type": "str"}, + "instance_pool_id": {"key": "properties.instancePoolId", "type": "str"}, + "maintenance_configuration_id": {"key": "properties.maintenanceConfigurationId", "type": "str"}, + "private_endpoint_connections": { + "key": "properties.privateEndpointConnections", + "type": "[ManagedInstancePecProperty]", + }, + "minimal_tls_version": {"key": "properties.minimalTlsVersion", "type": "str"}, + "current_backup_storage_redundancy": {"key": "properties.currentBackupStorageRedundancy", "type": "str"}, + "requested_backup_storage_redundancy": {"key": "properties.requestedBackupStorageRedundancy", "type": "str"}, + "zone_redundant": {"key": "properties.zoneRedundant", "type": "bool"}, + "primary_user_assigned_identity_id": {"key": "properties.primaryUserAssignedIdentityId", "type": "str"}, + "key_id": {"key": "properties.keyId", "type": "str"}, + "administrators": {"key": "properties.administrators", "type": "ManagedInstanceExternalAdministrator"}, + "service_principal": {"key": "properties.servicePrincipal", "type": "ServicePrincipal"}, + } + + def __init__( # pylint: disable=too-many-locals self, *, location: str, @@ -10016,9 +9923,9 @@ def __init__( **kwargs ): """ - :keyword location: Required. Resource location. + :keyword location: Resource location. Required. :paramtype location: str - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] :keyword identity: The Azure Active Directory identity of the managed instance. :paramtype identity: ~azure.mgmt.sql.models.ResourceIdentity @@ -10026,12 +9933,12 @@ def __init__( BC_Gen5. :paramtype sku: ~azure.mgmt.sql.models.Sku :keyword managed_instance_create_mode: Specifies the mode of database creation. - + Default: Regular instance creation. - + Restore: Creates an instance by restoring a set of backups to specific point in time. - RestorePointInTime and SourceManagedInstanceId must be specified. Known values are: "Default", - "PointInTimeRestore". + RestorePointInTime and SourceManagedInstanceId must be specified. Known values are: "Default" + and "PointInTimeRestore". :paramtype managed_instance_create_mode: str or ~azure.mgmt.sql.models.ManagedServerCreateMode :keyword administrator_login: Administrator username for the managed instance. Can only be specified when the managed instance is being created (and is required for creation). @@ -10043,7 +9950,7 @@ def __init__( :paramtype subnet_id: str :keyword license_type: The license type. Possible values are 'LicenseIncluded' (regular price inclusive of a new SQL license) and 'BasePrice' (discounted AHB price for bringing your own SQL - licenses). Known values are: "LicenseIncluded", "BasePrice". + licenses). Known values are: "LicenseIncluded" and "BasePrice". :paramtype license_type: str or ~azure.mgmt.sql.models.ManagedInstanceLicenseType :keyword v_cores: The number of vCores. Allowed values: 8, 16, 24, 32, 40, 64, 80. :paramtype v_cores: int @@ -10064,7 +9971,7 @@ def __init__( database that will be restored to create the new database. :paramtype restore_point_in_time: ~datetime.datetime :keyword proxy_override: Connection type used for connecting to the instance. Known values are: - "Proxy", "Redirect", "Default". + "Proxy", "Redirect", and "Default". :paramtype proxy_override: str or ~azure.mgmt.sql.models.ManagedInstanceProxyOverride :keyword timezone_id: Id of the timezone. Allowed values are timezones supported by Windows. Windows keeps details on supported timezones, including the id, in registry under @@ -10085,7 +9992,7 @@ def __init__( :keyword requested_backup_storage_redundancy: The storage account type to be used to store backups for this instance. The options are Local (LocallyRedundantStorage), Zone (ZoneRedundantStorage), Geo (GeoRedundantStorage) and GeoZone(GeoZoneRedundantStorage). Known - values are: "Geo", "Local", "Zone", "GeoZone". + values are: "Geo", "Local", "Zone", and "GeoZone". :paramtype requested_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy :keyword zone_redundant: Whether or not the multi-az is enabled. @@ -10100,7 +10007,7 @@ def __init__( :keyword service_principal: The managed instance's service principal. :paramtype service_principal: ~azure.mgmt.sql.models.ServicePrincipal """ - super(ManagedInstance, self).__init__(location=location, tags=tags, **kwargs) + super().__init__(location=location, tags=tags, **kwargs) self.identity = identity self.sku = sku self.provisioning_state = None @@ -10145,8 +10052,7 @@ class ManagedInstanceAdministrator(ProxyResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar administrator_type: Type of the managed instance administrator. Known values are: - "ActiveDirectory". + :ivar administrator_type: Type of the managed instance administrator. "ActiveDirectory" :vartype administrator_type: str or ~azure.mgmt.sql.models.ManagedInstanceAdministratorType :ivar login: Login name of the managed instance administrator. :vartype login: str @@ -10157,19 +10063,19 @@ class ManagedInstanceAdministrator(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'administrator_type': {'key': 'properties.administratorType', 'type': 'str'}, - 'login': {'key': 'properties.login', 'type': 'str'}, - 'sid': {'key': 'properties.sid', 'type': 'str'}, - 'tenant_id': {'key': 'properties.tenantId', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "administrator_type": {"key": "properties.administratorType", "type": "str"}, + "login": {"key": "properties.login", "type": "str"}, + "sid": {"key": "properties.sid", "type": "str"}, + "tenant_id": {"key": "properties.tenantId", "type": "str"}, } def __init__( @@ -10182,8 +10088,7 @@ def __init__( **kwargs ): """ - :keyword administrator_type: Type of the managed instance administrator. Known values are: - "ActiveDirectory". + :keyword administrator_type: Type of the managed instance administrator. "ActiveDirectory" :paramtype administrator_type: str or ~azure.mgmt.sql.models.ManagedInstanceAdministratorType :keyword login: Login name of the managed instance administrator. :paramtype login: str @@ -10192,14 +10097,14 @@ def __init__( :keyword tenant_id: Tenant ID of the managed instance administrator. :paramtype tenant_id: str """ - super(ManagedInstanceAdministrator, self).__init__(**kwargs) + super().__init__(**kwargs) self.administrator_type = administrator_type self.login = login self.sid = sid self.tenant_id = tenant_id -class ManagedInstanceAdministratorListResult(msrest.serialization.Model): +class ManagedInstanceAdministratorListResult(_serialization.Model): """A list of managed instance administrators. Variables are only populated by the server, and will be ignored when sending a request. @@ -10211,22 +10116,97 @@ class ManagedInstanceAdministratorListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ManagedInstanceAdministrator]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ManagedInstanceAdministrator]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) + self.value = None + self.next_link = None + + +class ManagedInstanceAdvancedThreatProtection(ProxyResource): + """A managed instance Advanced Threat Protection. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Resource ID. + :vartype id: str + :ivar name: Resource name. + :vartype name: str + :ivar type: Resource type. + :vartype type: str + :ivar system_data: SystemData of AdvancedThreatProtectionResource. + :vartype system_data: ~azure.mgmt.sql.models.SystemData + :ivar state: Specifies the state of the Advanced Threat Protection, whether it is enabled or + disabled or a state has not been applied yet on the specific database or server. Known values + are: "New", "Enabled", and "Disabled". + :vartype state: str or ~azure.mgmt.sql.models.AdvancedThreatProtectionState + :ivar creation_time: Specifies the UTC creation time of the policy. + :vartype creation_time: ~datetime.datetime + """ + + _validation = { + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "system_data": {"readonly": True}, + "creation_time": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "system_data": {"key": "systemData", "type": "SystemData"}, + "state": {"key": "properties.state", "type": "str"}, + "creation_time": {"key": "properties.creationTime", "type": "iso-8601"}, + } + + def __init__(self, *, state: Optional[Union[str, "_models.AdvancedThreatProtectionState"]] = None, **kwargs): """ + :keyword state: Specifies the state of the Advanced Threat Protection, whether it is enabled or + disabled or a state has not been applied yet on the specific database or server. Known values + are: "New", "Enabled", and "Disabled". + :paramtype state: str or ~azure.mgmt.sql.models.AdvancedThreatProtectionState """ - super(ManagedInstanceAdministratorListResult, self).__init__(**kwargs) + super().__init__(**kwargs) + self.system_data = None + self.state = state + self.creation_time = None + + +class ManagedInstanceAdvancedThreatProtectionListResult(_serialization.Model): + """A list of the managed instance's Advanced Threat Protection settings. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: Array of results. + :vartype value: list[~azure.mgmt.sql.models.ManagedInstanceAdvancedThreatProtection] + :ivar next_link: Link to retrieve next page of results. + :vartype next_link: str + """ + + _validation = { + "value": {"readonly": True}, + "next_link": {"readonly": True}, + } + + _attribute_map = { + "value": {"key": "value", "type": "[ManagedInstanceAdvancedThreatProtection]"}, + "next_link": {"key": "nextLink", "type": "str"}, + } + + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -10247,33 +10227,28 @@ class ManagedInstanceAzureADOnlyAuthentication(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'azure_ad_only_authentication': {'key': 'properties.azureADOnlyAuthentication', 'type': 'bool'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "azure_ad_only_authentication": {"key": "properties.azureADOnlyAuthentication", "type": "bool"}, } - def __init__( - self, - *, - azure_ad_only_authentication: Optional[bool] = None, - **kwargs - ): + def __init__(self, *, azure_ad_only_authentication: Optional[bool] = None, **kwargs): """ :keyword azure_ad_only_authentication: Azure Active Directory only Authentication enabled. :paramtype azure_ad_only_authentication: bool """ - super(ManagedInstanceAzureADOnlyAuthentication, self).__init__(**kwargs) + super().__init__(**kwargs) self.azure_ad_only_authentication = azure_ad_only_authentication -class ManagedInstanceAzureADOnlyAuthListResult(msrest.serialization.Model): +class ManagedInstanceAzureADOnlyAuthListResult(_serialization.Model): """A list of active directory only authentications. Variables are only populated by the server, and will be ignored when sending a request. @@ -10285,27 +10260,206 @@ class ManagedInstanceAzureADOnlyAuthListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, + } + + _attribute_map = { + "value": {"key": "value", "type": "[ManagedInstanceAzureADOnlyAuthentication]"}, + "next_link": {"key": "nextLink", "type": "str"}, + } + + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) + self.value = None + self.next_link = None + + +class ManagedInstanceDtc(ProxyResource): + """SQL Managed Instance DTC. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Resource ID. + :vartype id: str + :ivar name: Resource name. + :vartype name: str + :ivar type: Resource type. + :vartype type: str + :ivar dtc_enabled: Active status of managed instance DTC. + :vartype dtc_enabled: bool + :ivar security_settings: Security settings of managed instance DTC. + :vartype security_settings: ~azure.mgmt.sql.models.ManagedInstanceDtcSecuritySettings + :ivar external_dns_suffix_search_list: External dns suffix search list of managed instance DTC. + :vartype external_dns_suffix_search_list: list[str] + :ivar dtc_host_name_dns_suffix: Host name dns suffix of managed instance DTC. + :vartype dtc_host_name_dns_suffix: str + :ivar provisioning_state: Provisioning state of managed instance DTC. Known values are: + "Created", "InProgress", "Succeeded", "Failed", and "Canceled". + :vartype provisioning_state: str or ~azure.mgmt.sql.models.ProvisioningState + """ + + _validation = { + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "dtc_host_name_dns_suffix": {"readonly": True}, + "provisioning_state": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ManagedInstanceAzureADOnlyAuthentication]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "dtc_enabled": {"key": "properties.dtcEnabled", "type": "bool"}, + "security_settings": {"key": "properties.securitySettings", "type": "ManagedInstanceDtcSecuritySettings"}, + "external_dns_suffix_search_list": {"key": "properties.externalDnsSuffixSearchList", "type": "[str]"}, + "dtc_host_name_dns_suffix": {"key": "properties.dtcHostNameDnsSuffix", "type": "str"}, + "provisioning_state": {"key": "properties.provisioningState", "type": "str"}, } def __init__( self, + *, + dtc_enabled: Optional[bool] = None, + security_settings: Optional["_models.ManagedInstanceDtcSecuritySettings"] = None, + external_dns_suffix_search_list: Optional[List[str]] = None, **kwargs ): """ + :keyword dtc_enabled: Active status of managed instance DTC. + :paramtype dtc_enabled: bool + :keyword security_settings: Security settings of managed instance DTC. + :paramtype security_settings: ~azure.mgmt.sql.models.ManagedInstanceDtcSecuritySettings + :keyword external_dns_suffix_search_list: External dns suffix search list of managed instance + DTC. + :paramtype external_dns_suffix_search_list: list[str] """ - super(ManagedInstanceAzureADOnlyAuthListResult, self).__init__(**kwargs) + super().__init__(**kwargs) + self.dtc_enabled = dtc_enabled + self.security_settings = security_settings + self.external_dns_suffix_search_list = external_dns_suffix_search_list + self.dtc_host_name_dns_suffix = None + self.provisioning_state = None + + +class ManagedInstanceDtcListResult(_serialization.Model): + """A list of managed instance's DTCs. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: Array of results. + :vartype value: list[~azure.mgmt.sql.models.ManagedInstanceDtc] + :ivar next_link: Link to retrieve next page of results. + :vartype next_link: str + """ + + _validation = { + "value": {"readonly": True}, + "next_link": {"readonly": True}, + } + + _attribute_map = { + "value": {"key": "value", "type": "[ManagedInstanceDtc]"}, + "next_link": {"key": "nextLink", "type": "str"}, + } + + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ManagedInstanceEditionCapability(msrest.serialization.Model): +class ManagedInstanceDtcSecuritySettings(_serialization.Model): + """The Security Settings of managed instance DTC. + + :ivar transaction_manager_communication_settings: Transaction Manager communication settings of + managed instance DTC. + :vartype transaction_manager_communication_settings: + ~azure.mgmt.sql.models.ManagedInstanceDtcTransactionManagerCommunicationSettings + :ivar xa_transactions_enabled: Allow XA Transactions to managed instance DTC. + :vartype xa_transactions_enabled: bool + :ivar sna_lu6_point2_transactions_enabled: Allow SNA LU 6.2 to managed instance DTC. + :vartype sna_lu6_point2_transactions_enabled: bool + """ + + _attribute_map = { + "transaction_manager_communication_settings": { + "key": "transactionManagerCommunicationSettings", + "type": "ManagedInstanceDtcTransactionManagerCommunicationSettings", + }, + "xa_transactions_enabled": {"key": "xaTransactionsEnabled", "type": "bool"}, + "sna_lu6_point2_transactions_enabled": {"key": "snaLu6point2TransactionsEnabled", "type": "bool"}, + } + + def __init__( + self, + *, + transaction_manager_communication_settings: Optional[ + "_models.ManagedInstanceDtcTransactionManagerCommunicationSettings" + ] = None, + xa_transactions_enabled: Optional[bool] = None, + sna_lu6_point2_transactions_enabled: Optional[bool] = None, + **kwargs + ): + """ + :keyword transaction_manager_communication_settings: Transaction Manager communication settings + of managed instance DTC. + :paramtype transaction_manager_communication_settings: + ~azure.mgmt.sql.models.ManagedInstanceDtcTransactionManagerCommunicationSettings + :keyword xa_transactions_enabled: Allow XA Transactions to managed instance DTC. + :paramtype xa_transactions_enabled: bool + :keyword sna_lu6_point2_transactions_enabled: Allow SNA LU 6.2 to managed instance DTC. + :paramtype sna_lu6_point2_transactions_enabled: bool + """ + super().__init__(**kwargs) + self.transaction_manager_communication_settings = transaction_manager_communication_settings + self.xa_transactions_enabled = xa_transactions_enabled + self.sna_lu6_point2_transactions_enabled = sna_lu6_point2_transactions_enabled + + +class ManagedInstanceDtcTransactionManagerCommunicationSettings(_serialization.Model): + """The Transaction Manager Communication Settings of managed instance DTC. + + :ivar allow_inbound_enabled: Allow Inbound traffic to managed instance DTC. + :vartype allow_inbound_enabled: bool + :ivar allow_outbound_enabled: Allow Outbound traffic of managed instance DTC. + :vartype allow_outbound_enabled: bool + :ivar authentication: Authentication type of managed instance DTC. + :vartype authentication: str + """ + + _attribute_map = { + "allow_inbound_enabled": {"key": "allowInboundEnabled", "type": "bool"}, + "allow_outbound_enabled": {"key": "allowOutboundEnabled", "type": "bool"}, + "authentication": {"key": "authentication", "type": "str"}, + } + + def __init__( + self, + *, + allow_inbound_enabled: Optional[bool] = None, + allow_outbound_enabled: Optional[bool] = None, + authentication: Optional[str] = None, + **kwargs + ): + """ + :keyword allow_inbound_enabled: Allow Inbound traffic to managed instance DTC. + :paramtype allow_inbound_enabled: bool + :keyword allow_outbound_enabled: Allow Outbound traffic of managed instance DTC. + :paramtype allow_outbound_enabled: bool + :keyword authentication: Authentication type of managed instance DTC. + :paramtype authentication: str + """ + super().__init__(**kwargs) + self.allow_inbound_enabled = allow_inbound_enabled + self.allow_outbound_enabled = allow_outbound_enabled + self.authentication = authentication + + +class ManagedInstanceEditionCapability(_serialization.Model): """The managed server capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -10320,40 +10474,35 @@ class ManagedInstanceEditionCapability(msrest.serialization.Model): :ivar zone_redundant: Whether or not zone redundancy is supported for the edition. :vartype zone_redundant: bool :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'name': {'readonly': True}, - 'supported_families': {'readonly': True}, - 'supported_storage_capabilities': {'readonly': True}, - 'zone_redundant': {'readonly': True}, - 'status': {'readonly': True}, + "name": {"readonly": True}, + "supported_families": {"readonly": True}, + "supported_storage_capabilities": {"readonly": True}, + "zone_redundant": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'supported_families': {'key': 'supportedFamilies', 'type': '[ManagedInstanceFamilyCapability]'}, - 'supported_storage_capabilities': {'key': 'supportedStorageCapabilities', 'type': '[StorageCapability]'}, - 'zone_redundant': {'key': 'zoneRedundant', 'type': 'bool'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "name": {"key": "name", "type": "str"}, + "supported_families": {"key": "supportedFamilies", "type": "[ManagedInstanceFamilyCapability]"}, + "supported_storage_capabilities": {"key": "supportedStorageCapabilities", "type": "[StorageCapability]"}, + "zone_redundant": {"key": "zoneRedundant", "type": "bool"}, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(ManagedInstanceEditionCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.name = None self.supported_families = None self.supported_storage_capabilities = None @@ -10379,7 +10528,7 @@ class ManagedInstanceEncryptionProtector(ProxyResource): :ivar server_key_name: The name of the managed instance key. :vartype server_key_name: str :ivar server_key_type: The encryption protector type like 'ServiceManaged', 'AzureKeyVault'. - Known values are: "ServiceManaged", "AzureKeyVault". + Known values are: "ServiceManaged" and "AzureKeyVault". :vartype server_key_type: str or ~azure.mgmt.sql.models.ServerKeyType :ivar uri: The URI of the server key. :vartype uri: str @@ -10390,24 +10539,24 @@ class ManagedInstanceEncryptionProtector(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'kind': {'readonly': True}, - 'uri': {'readonly': True}, - 'thumbprint': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "kind": {"readonly": True}, + "uri": {"readonly": True}, + "thumbprint": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'kind': {'key': 'kind', 'type': 'str'}, - 'server_key_name': {'key': 'properties.serverKeyName', 'type': 'str'}, - 'server_key_type': {'key': 'properties.serverKeyType', 'type': 'str'}, - 'uri': {'key': 'properties.uri', 'type': 'str'}, - 'thumbprint': {'key': 'properties.thumbprint', 'type': 'str'}, - 'auto_rotation_enabled': {'key': 'properties.autoRotationEnabled', 'type': 'bool'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "kind": {"key": "kind", "type": "str"}, + "server_key_name": {"key": "properties.serverKeyName", "type": "str"}, + "server_key_type": {"key": "properties.serverKeyType", "type": "str"}, + "uri": {"key": "properties.uri", "type": "str"}, + "thumbprint": {"key": "properties.thumbprint", "type": "str"}, + "auto_rotation_enabled": {"key": "properties.autoRotationEnabled", "type": "bool"}, } def __init__( @@ -10422,12 +10571,12 @@ def __init__( :keyword server_key_name: The name of the managed instance key. :paramtype server_key_name: str :keyword server_key_type: The encryption protector type like 'ServiceManaged', 'AzureKeyVault'. - Known values are: "ServiceManaged", "AzureKeyVault". + Known values are: "ServiceManaged" and "AzureKeyVault". :paramtype server_key_type: str or ~azure.mgmt.sql.models.ServerKeyType :keyword auto_rotation_enabled: Key auto rotation opt-in flag. Either true or false. :paramtype auto_rotation_enabled: bool """ - super(ManagedInstanceEncryptionProtector, self).__init__(**kwargs) + super().__init__(**kwargs) self.kind = None self.server_key_name = server_key_name self.server_key_type = server_key_type @@ -10436,7 +10585,7 @@ def __init__( self.auto_rotation_enabled = auto_rotation_enabled -class ManagedInstanceEncryptionProtectorListResult(msrest.serialization.Model): +class ManagedInstanceEncryptionProtectorListResult(_serialization.Model): """A list of managed instance encryption protectors. Variables are only populated by the server, and will be ignored when sending a request. @@ -10448,33 +10597,29 @@ class ManagedInstanceEncryptionProtectorListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ManagedInstanceEncryptionProtector]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ManagedInstanceEncryptionProtector]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedInstanceEncryptionProtectorListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ManagedInstanceExternalAdministrator(msrest.serialization.Model): +class ManagedInstanceExternalAdministrator(_serialization.Model): """Properties of a active directory administrator. - :ivar administrator_type: Type of the sever administrator. Known values are: "ActiveDirectory". + :ivar administrator_type: Type of the sever administrator. "ActiveDirectory" :vartype administrator_type: str or ~azure.mgmt.sql.models.AdministratorType :ivar principal_type: Principal Type of the sever administrator. Known values are: "User", - "Group", "Application". + "Group", and "Application". :vartype principal_type: str or ~azure.mgmt.sql.models.PrincipalType :ivar login: Login name of the server administrator. :vartype login: str @@ -10487,12 +10632,12 @@ class ManagedInstanceExternalAdministrator(msrest.serialization.Model): """ _attribute_map = { - 'administrator_type': {'key': 'administratorType', 'type': 'str'}, - 'principal_type': {'key': 'principalType', 'type': 'str'}, - 'login': {'key': 'login', 'type': 'str'}, - 'sid': {'key': 'sid', 'type': 'str'}, - 'tenant_id': {'key': 'tenantId', 'type': 'str'}, - 'azure_ad_only_authentication': {'key': 'azureADOnlyAuthentication', 'type': 'bool'}, + "administrator_type": {"key": "administratorType", "type": "str"}, + "principal_type": {"key": "principalType", "type": "str"}, + "login": {"key": "login", "type": "str"}, + "sid": {"key": "sid", "type": "str"}, + "tenant_id": {"key": "tenantId", "type": "str"}, + "azure_ad_only_authentication": {"key": "azureADOnlyAuthentication", "type": "bool"}, } def __init__( @@ -10507,11 +10652,10 @@ def __init__( **kwargs ): """ - :keyword administrator_type: Type of the sever administrator. Known values are: - "ActiveDirectory". + :keyword administrator_type: Type of the sever administrator. "ActiveDirectory" :paramtype administrator_type: str or ~azure.mgmt.sql.models.AdministratorType :keyword principal_type: Principal Type of the sever administrator. Known values are: "User", - "Group", "Application". + "Group", and "Application". :paramtype principal_type: str or ~azure.mgmt.sql.models.PrincipalType :keyword login: Login name of the server administrator. :paramtype login: str @@ -10522,7 +10666,7 @@ def __init__( :keyword azure_ad_only_authentication: Azure Active Directory only Authentication enabled. :paramtype azure_ad_only_authentication: bool """ - super(ManagedInstanceExternalAdministrator, self).__init__(**kwargs) + super().__init__(**kwargs) self.administrator_type = administrator_type self.principal_type = principal_type self.login = login @@ -10531,7 +10675,7 @@ def __init__( self.azure_ad_only_authentication = azure_ad_only_authentication -class ManagedInstanceFamilyCapability(msrest.serialization.Model): +class ManagedInstanceFamilyCapability(_serialization.Model): """The managed server family capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -10545,40 +10689,35 @@ class ManagedInstanceFamilyCapability(msrest.serialization.Model): :ivar supported_vcores_values: List of supported virtual cores values. :vartype supported_vcores_values: list[~azure.mgmt.sql.models.ManagedInstanceVcoresCapability] :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'name': {'readonly': True}, - 'sku': {'readonly': True}, - 'supported_license_types': {'readonly': True}, - 'supported_vcores_values': {'readonly': True}, - 'status': {'readonly': True}, + "name": {"readonly": True}, + "sku": {"readonly": True}, + "supported_license_types": {"readonly": True}, + "supported_vcores_values": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'sku': {'key': 'sku', 'type': 'str'}, - 'supported_license_types': {'key': 'supportedLicenseTypes', 'type': '[LicenseTypeCapability]'}, - 'supported_vcores_values': {'key': 'supportedVcoresValues', 'type': '[ManagedInstanceVcoresCapability]'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "name": {"key": "name", "type": "str"}, + "sku": {"key": "sku", "type": "str"}, + "supported_license_types": {"key": "supportedLicenseTypes", "type": "[LicenseTypeCapability]"}, + "supported_vcores_values": {"key": "supportedVcoresValues", "type": "[ManagedInstanceVcoresCapability]"}, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(ManagedInstanceFamilyCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.name = None self.sku = None self.supported_license_types = None @@ -10602,7 +10741,7 @@ class ManagedInstanceKey(ProxyResource): experience. :vartype kind: str :ivar server_key_type: The key type like 'ServiceManaged', 'AzureKeyVault'. Known values are: - "ServiceManaged", "AzureKeyVault". + "ServiceManaged" and "AzureKeyVault". :vartype server_key_type: str or ~azure.mgmt.sql.models.ServerKeyType :ivar uri: The URI of the key. If the ServerKeyType is AzureKeyVault, then the URI is required. :vartype uri: str @@ -10615,25 +10754,25 @@ class ManagedInstanceKey(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'kind': {'readonly': True}, - 'thumbprint': {'readonly': True}, - 'creation_date': {'readonly': True}, - 'auto_rotation_enabled': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "kind": {"readonly": True}, + "thumbprint": {"readonly": True}, + "creation_date": {"readonly": True}, + "auto_rotation_enabled": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'kind': {'key': 'kind', 'type': 'str'}, - 'server_key_type': {'key': 'properties.serverKeyType', 'type': 'str'}, - 'uri': {'key': 'properties.uri', 'type': 'str'}, - 'thumbprint': {'key': 'properties.thumbprint', 'type': 'str'}, - 'creation_date': {'key': 'properties.creationDate', 'type': 'iso-8601'}, - 'auto_rotation_enabled': {'key': 'properties.autoRotationEnabled', 'type': 'bool'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "kind": {"key": "kind", "type": "str"}, + "server_key_type": {"key": "properties.serverKeyType", "type": "str"}, + "uri": {"key": "properties.uri", "type": "str"}, + "thumbprint": {"key": "properties.thumbprint", "type": "str"}, + "creation_date": {"key": "properties.creationDate", "type": "iso-8601"}, + "auto_rotation_enabled": {"key": "properties.autoRotationEnabled", "type": "bool"}, } def __init__( @@ -10645,13 +10784,13 @@ def __init__( ): """ :keyword server_key_type: The key type like 'ServiceManaged', 'AzureKeyVault'. Known values - are: "ServiceManaged", "AzureKeyVault". + are: "ServiceManaged" and "AzureKeyVault". :paramtype server_key_type: str or ~azure.mgmt.sql.models.ServerKeyType :keyword uri: The URI of the key. If the ServerKeyType is AzureKeyVault, then the URI is required. :paramtype uri: str """ - super(ManagedInstanceKey, self).__init__(**kwargs) + super().__init__(**kwargs) self.kind = None self.server_key_type = server_key_type self.uri = uri @@ -10660,7 +10799,7 @@ def __init__( self.auto_rotation_enabled = None -class ManagedInstanceKeyListResult(msrest.serialization.Model): +class ManagedInstanceKeyListResult(_serialization.Model): """A list of managed instance keys. Variables are only populated by the server, and will be ignored when sending a request. @@ -10672,27 +10811,23 @@ class ManagedInstanceKeyListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ManagedInstanceKey]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ManagedInstanceKey]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedInstanceKeyListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ManagedInstanceListResult(msrest.serialization.Model): +class ManagedInstanceListResult(_serialization.Model): """A list of managed instances. Variables are only populated by the server, and will be ignored when sending a request. @@ -10704,22 +10839,18 @@ class ManagedInstanceListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ManagedInstance]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ManagedInstance]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedInstanceListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -10748,43 +10879,39 @@ class ManagedInstanceLongTermRetentionBackup(ProxyResource): :ivar backup_expiration_time: The time the long term retention backup will expire. :vartype backup_expiration_time: ~datetime.datetime :ivar backup_storage_redundancy: The storage redundancy type of the backup. Known values are: - "Geo", "Local", "Zone", "GeoZone". + "Geo", "Local", "Zone", and "GeoZone". :vartype backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'managed_instance_name': {'readonly': True}, - 'managed_instance_create_time': {'readonly': True}, - 'database_name': {'readonly': True}, - 'database_deletion_time': {'readonly': True}, - 'backup_time': {'readonly': True}, - 'backup_expiration_time': {'readonly': True}, - 'backup_storage_redundancy': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "managed_instance_name": {"readonly": True}, + "managed_instance_create_time": {"readonly": True}, + "database_name": {"readonly": True}, + "database_deletion_time": {"readonly": True}, + "backup_time": {"readonly": True}, + "backup_expiration_time": {"readonly": True}, + "backup_storage_redundancy": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'managed_instance_name': {'key': 'properties.managedInstanceName', 'type': 'str'}, - 'managed_instance_create_time': {'key': 'properties.managedInstanceCreateTime', 'type': 'iso-8601'}, - 'database_name': {'key': 'properties.databaseName', 'type': 'str'}, - 'database_deletion_time': {'key': 'properties.databaseDeletionTime', 'type': 'iso-8601'}, - 'backup_time': {'key': 'properties.backupTime', 'type': 'iso-8601'}, - 'backup_expiration_time': {'key': 'properties.backupExpirationTime', 'type': 'iso-8601'}, - 'backup_storage_redundancy': {'key': 'properties.backupStorageRedundancy', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "managed_instance_name": {"key": "properties.managedInstanceName", "type": "str"}, + "managed_instance_create_time": {"key": "properties.managedInstanceCreateTime", "type": "iso-8601"}, + "database_name": {"key": "properties.databaseName", "type": "str"}, + "database_deletion_time": {"key": "properties.databaseDeletionTime", "type": "iso-8601"}, + "backup_time": {"key": "properties.backupTime", "type": "iso-8601"}, + "backup_expiration_time": {"key": "properties.backupExpirationTime", "type": "iso-8601"}, + "backup_storage_redundancy": {"key": "properties.backupStorageRedundancy", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedInstanceLongTermRetentionBackup, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.managed_instance_name = None self.managed_instance_create_time = None self.database_name = None @@ -10794,7 +10921,7 @@ def __init__( self.backup_storage_redundancy = None -class ManagedInstanceLongTermRetentionBackupListResult(msrest.serialization.Model): +class ManagedInstanceLongTermRetentionBackupListResult(_serialization.Model): """A list of long term retention backups for managed database(s). Variables are only populated by the server, and will be ignored when sending a request. @@ -10806,22 +10933,18 @@ class ManagedInstanceLongTermRetentionBackupListResult(msrest.serialization.Mode """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ManagedInstanceLongTermRetentionBackup]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ManagedInstanceLongTermRetentionBackup]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedInstanceLongTermRetentionBackupListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -10848,19 +10971,19 @@ class ManagedInstanceLongTermRetentionPolicy(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'weekly_retention': {'key': 'properties.weeklyRetention', 'type': 'str'}, - 'monthly_retention': {'key': 'properties.monthlyRetention', 'type': 'str'}, - 'yearly_retention': {'key': 'properties.yearlyRetention', 'type': 'str'}, - 'week_of_year': {'key': 'properties.weekOfYear', 'type': 'int'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "weekly_retention": {"key": "properties.weeklyRetention", "type": "str"}, + "monthly_retention": {"key": "properties.monthlyRetention", "type": "str"}, + "yearly_retention": {"key": "properties.yearlyRetention", "type": "str"}, + "week_of_year": {"key": "properties.weekOfYear", "type": "int"}, } def __init__( @@ -10883,14 +11006,14 @@ def __init__( :keyword week_of_year: The week of year to take the yearly backup in an ISO 8601 format. :paramtype week_of_year: int """ - super(ManagedInstanceLongTermRetentionPolicy, self).__init__(**kwargs) + super().__init__(**kwargs) self.weekly_retention = weekly_retention self.monthly_retention = monthly_retention self.yearly_retention = yearly_retention self.week_of_year = week_of_year -class ManagedInstanceLongTermRetentionPolicyListResult(msrest.serialization.Model): +class ManagedInstanceLongTermRetentionPolicyListResult(_serialization.Model): """A list of long term retention policies. Variables are only populated by the server, and will be ignored when sending a request. @@ -10902,27 +11025,23 @@ class ManagedInstanceLongTermRetentionPolicyListResult(msrest.serialization.Mode """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ManagedInstanceLongTermRetentionPolicy]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ManagedInstanceLongTermRetentionPolicy]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedInstanceLongTermRetentionPolicyListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ManagedInstanceMaintenanceConfigurationCapability(msrest.serialization.Model): +class ManagedInstanceMaintenanceConfigurationCapability(_serialization.Model): """The maintenance configuration capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -10930,40 +11049,35 @@ class ManagedInstanceMaintenanceConfigurationCapability(msrest.serialization.Mod :ivar name: Maintenance configuration name. :vartype name: str :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'name': {'readonly': True}, - 'status': {'readonly': True}, + "name": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "name": {"key": "name", "type": "str"}, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(ManagedInstanceMaintenanceConfigurationCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.name = None self.status = None self.reason = reason -class ManagedInstanceOperation(ProxyResource): +class ManagedInstanceOperation(ProxyResource): # pylint: disable=too-many-instance-attributes """A managed instance operation. Variables are only populated by the server, and will be ignored when sending a request. @@ -10986,7 +11100,7 @@ class ManagedInstanceOperation(ProxyResource): :ivar start_time: The operation start time. :vartype start_time: ~datetime.datetime :ivar state: The operation state. Known values are: "Pending", "InProgress", "Succeeded", - "Failed", "CancelInProgress", "Cancelled". + "Failed", "CancelInProgress", and "Cancelled". :vartype state: str or ~azure.mgmt.sql.models.ManagementOperationState :ivar error_code: The operation error code. :vartype error_code: int @@ -11009,54 +11123,53 @@ class ManagedInstanceOperation(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'managed_instance_name': {'readonly': True}, - 'operation': {'readonly': True}, - 'operation_friendly_name': {'readonly': True}, - 'percent_complete': {'readonly': True}, - 'start_time': {'readonly': True}, - 'state': {'readonly': True}, - 'error_code': {'readonly': True}, - 'error_description': {'readonly': True}, - 'error_severity': {'readonly': True}, - 'is_user_error': {'readonly': True}, - 'estimated_completion_time': {'readonly': True}, - 'description': {'readonly': True}, - 'is_cancellable': {'readonly': True}, - 'operation_parameters': {'readonly': True}, - 'operation_steps': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'managed_instance_name': {'key': 'properties.managedInstanceName', 'type': 'str'}, - 'operation': {'key': 'properties.operation', 'type': 'str'}, - 'operation_friendly_name': {'key': 'properties.operationFriendlyName', 'type': 'str'}, - 'percent_complete': {'key': 'properties.percentComplete', 'type': 'int'}, - 'start_time': {'key': 'properties.startTime', 'type': 'iso-8601'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'error_code': {'key': 'properties.errorCode', 'type': 'int'}, - 'error_description': {'key': 'properties.errorDescription', 'type': 'str'}, - 'error_severity': {'key': 'properties.errorSeverity', 'type': 'int'}, - 'is_user_error': {'key': 'properties.isUserError', 'type': 'bool'}, - 'estimated_completion_time': {'key': 'properties.estimatedCompletionTime', 'type': 'iso-8601'}, - 'description': {'key': 'properties.description', 'type': 'str'}, - 'is_cancellable': {'key': 'properties.isCancellable', 'type': 'bool'}, - 'operation_parameters': {'key': 'properties.operationParameters', 'type': 'ManagedInstanceOperationParametersPair'}, - 'operation_steps': {'key': 'properties.operationSteps', 'type': 'ManagedInstanceOperationSteps'}, - } - - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedInstanceOperation, self).__init__(**kwargs) + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "managed_instance_name": {"readonly": True}, + "operation": {"readonly": True}, + "operation_friendly_name": {"readonly": True}, + "percent_complete": {"readonly": True}, + "start_time": {"readonly": True}, + "state": {"readonly": True}, + "error_code": {"readonly": True}, + "error_description": {"readonly": True}, + "error_severity": {"readonly": True}, + "is_user_error": {"readonly": True}, + "estimated_completion_time": {"readonly": True}, + "description": {"readonly": True}, + "is_cancellable": {"readonly": True}, + "operation_parameters": {"readonly": True}, + "operation_steps": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "managed_instance_name": {"key": "properties.managedInstanceName", "type": "str"}, + "operation": {"key": "properties.operation", "type": "str"}, + "operation_friendly_name": {"key": "properties.operationFriendlyName", "type": "str"}, + "percent_complete": {"key": "properties.percentComplete", "type": "int"}, + "start_time": {"key": "properties.startTime", "type": "iso-8601"}, + "state": {"key": "properties.state", "type": "str"}, + "error_code": {"key": "properties.errorCode", "type": "int"}, + "error_description": {"key": "properties.errorDescription", "type": "str"}, + "error_severity": {"key": "properties.errorSeverity", "type": "int"}, + "is_user_error": {"key": "properties.isUserError", "type": "bool"}, + "estimated_completion_time": {"key": "properties.estimatedCompletionTime", "type": "iso-8601"}, + "description": {"key": "properties.description", "type": "str"}, + "is_cancellable": {"key": "properties.isCancellable", "type": "bool"}, + "operation_parameters": { + "key": "properties.operationParameters", + "type": "ManagedInstanceOperationParametersPair", + }, + "operation_steps": {"key": "properties.operationSteps", "type": "ManagedInstanceOperationSteps"}, + } + + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.managed_instance_name = None self.operation = None self.operation_friendly_name = None @@ -11074,7 +11187,7 @@ def __init__( self.operation_steps = None -class ManagedInstanceOperationListResult(msrest.serialization.Model): +class ManagedInstanceOperationListResult(_serialization.Model): """The response to a list managed instance operations request. Variables are only populated by the server, and will be ignored when sending a request. @@ -11086,27 +11199,23 @@ class ManagedInstanceOperationListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ManagedInstanceOperation]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ManagedInstanceOperation]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedInstanceOperationListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ManagedInstanceOperationParametersPair(msrest.serialization.Model): +class ManagedInstanceOperationParametersPair(_serialization.Model): """The parameters of a managed instance operation. Variables are only populated by the server, and will be ignored when sending a request. @@ -11118,27 +11227,23 @@ class ManagedInstanceOperationParametersPair(msrest.serialization.Model): """ _validation = { - 'current_parameters': {'readonly': True}, - 'requested_parameters': {'readonly': True}, + "current_parameters": {"readonly": True}, + "requested_parameters": {"readonly": True}, } _attribute_map = { - 'current_parameters': {'key': 'currentParameters', 'type': 'UpsertManagedServerOperationParameters'}, - 'requested_parameters': {'key': 'requestedParameters', 'type': 'UpsertManagedServerOperationParameters'}, + "current_parameters": {"key": "currentParameters", "type": "UpsertManagedServerOperationParameters"}, + "requested_parameters": {"key": "requestedParameters", "type": "UpsertManagedServerOperationParameters"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedInstanceOperationParametersPair, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.current_parameters = None self.requested_parameters = None -class ManagedInstanceOperationSteps(msrest.serialization.Model): +class ManagedInstanceOperationSteps(_serialization.Model): """The steps of a managed instance operation. Variables are only populated by the server, and will be ignored when sending a request. @@ -11152,30 +11257,26 @@ class ManagedInstanceOperationSteps(msrest.serialization.Model): """ _validation = { - 'total_steps': {'readonly': True}, - 'current_step': {'readonly': True}, - 'steps_list': {'readonly': True}, + "total_steps": {"readonly": True}, + "current_step": {"readonly": True}, + "steps_list": {"readonly": True}, } _attribute_map = { - 'total_steps': {'key': 'totalSteps', 'type': 'str'}, - 'current_step': {'key': 'currentStep', 'type': 'int'}, - 'steps_list': {'key': 'stepsList', 'type': '[UpsertManagedServerOperationStep]'}, + "total_steps": {"key": "totalSteps", "type": "str"}, + "current_step": {"key": "currentStep", "type": "int"}, + "steps_list": {"key": "stepsList", "type": "[UpsertManagedServerOperationStep]"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedInstanceOperationSteps, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.total_steps = None self.current_step = None self.steps_list = None -class ManagedInstancePairInfo(msrest.serialization.Model): +class ManagedInstancePairInfo(_serialization.Model): """Pairs of Managed Instances in the failover group. :ivar primary_managed_instance_id: Id of Primary Managed Instance in pair. @@ -11185,8 +11286,8 @@ class ManagedInstancePairInfo(msrest.serialization.Model): """ _attribute_map = { - 'primary_managed_instance_id': {'key': 'primaryManagedInstanceId', 'type': 'str'}, - 'partner_managed_instance_id': {'key': 'partnerManagedInstanceId', 'type': 'str'}, + "primary_managed_instance_id": {"key": "primaryManagedInstanceId", "type": "str"}, + "partner_managed_instance_id": {"key": "partnerManagedInstanceId", "type": "str"}, } def __init__( @@ -11202,12 +11303,12 @@ def __init__( :keyword partner_managed_instance_id: Id of Partner Managed Instance in pair. :paramtype partner_managed_instance_id: str """ - super(ManagedInstancePairInfo, self).__init__(**kwargs) + super().__init__(**kwargs) self.primary_managed_instance_id = primary_managed_instance_id self.partner_managed_instance_id = partner_managed_instance_id -class ManagedInstancePecProperty(msrest.serialization.Model): +class ManagedInstancePecProperty(_serialization.Model): """A private endpoint connection under a managed instance. Variables are only populated by the server, and will be ignored when sending a request. @@ -11219,22 +11320,18 @@ class ManagedInstancePecProperty(msrest.serialization.Model): """ _validation = { - 'id': {'readonly': True}, - 'properties': {'readonly': True}, + "id": {"readonly": True}, + "properties": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'properties': {'key': 'properties', 'type': 'ManagedInstancePrivateEndpointConnectionProperties'}, + "id": {"key": "id", "type": "str"}, + "properties": {"key": "properties", "type": "ManagedInstancePrivateEndpointConnectionProperties"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedInstancePecProperty, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.id = None self.properties = None @@ -11261,26 +11358,31 @@ class ManagedInstancePrivateEndpointConnection(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'provisioning_state': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "provisioning_state": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'private_endpoint': {'key': 'properties.privateEndpoint', 'type': 'ManagedInstancePrivateEndpointProperty'}, - 'private_link_service_connection_state': {'key': 'properties.privateLinkServiceConnectionState', 'type': 'ManagedInstancePrivateLinkServiceConnectionStateProperty'}, - 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "private_endpoint": {"key": "properties.privateEndpoint", "type": "ManagedInstancePrivateEndpointProperty"}, + "private_link_service_connection_state": { + "key": "properties.privateLinkServiceConnectionState", + "type": "ManagedInstancePrivateLinkServiceConnectionStateProperty", + }, + "provisioning_state": {"key": "properties.provisioningState", "type": "str"}, } def __init__( self, *, private_endpoint: Optional["_models.ManagedInstancePrivateEndpointProperty"] = None, - private_link_service_connection_state: Optional["_models.ManagedInstancePrivateLinkServiceConnectionStateProperty"] = None, + private_link_service_connection_state: Optional[ + "_models.ManagedInstancePrivateLinkServiceConnectionStateProperty" + ] = None, **kwargs ): """ @@ -11291,13 +11393,13 @@ def __init__( :paramtype private_link_service_connection_state: ~azure.mgmt.sql.models.ManagedInstancePrivateLinkServiceConnectionStateProperty """ - super(ManagedInstancePrivateEndpointConnection, self).__init__(**kwargs) + super().__init__(**kwargs) self.private_endpoint = private_endpoint self.private_link_service_connection_state = private_link_service_connection_state self.provisioning_state = None -class ManagedInstancePrivateEndpointConnectionListResult(msrest.serialization.Model): +class ManagedInstancePrivateEndpointConnectionListResult(_serialization.Model): """A list of private endpoint connections. Variables are only populated by the server, and will be ignored when sending a request. @@ -11309,27 +11411,23 @@ class ManagedInstancePrivateEndpointConnectionListResult(msrest.serialization.Mo """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ManagedInstancePrivateEndpointConnection]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ManagedInstancePrivateEndpointConnection]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedInstancePrivateEndpointConnectionListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ManagedInstancePrivateEndpointConnectionProperties(msrest.serialization.Model): +class ManagedInstancePrivateEndpointConnectionProperties(_serialization.Model): """Properties of a private endpoint connection. Variables are only populated by the server, and will be ignored when sending a request. @@ -11345,20 +11443,25 @@ class ManagedInstancePrivateEndpointConnectionProperties(msrest.serialization.Mo """ _validation = { - 'provisioning_state': {'readonly': True}, + "provisioning_state": {"readonly": True}, } _attribute_map = { - 'private_endpoint': {'key': 'privateEndpoint', 'type': 'ManagedInstancePrivateEndpointProperty'}, - 'private_link_service_connection_state': {'key': 'privateLinkServiceConnectionState', 'type': 'ManagedInstancePrivateLinkServiceConnectionStateProperty'}, - 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + "private_endpoint": {"key": "privateEndpoint", "type": "ManagedInstancePrivateEndpointProperty"}, + "private_link_service_connection_state": { + "key": "privateLinkServiceConnectionState", + "type": "ManagedInstancePrivateLinkServiceConnectionStateProperty", + }, + "provisioning_state": {"key": "provisioningState", "type": "str"}, } def __init__( self, *, private_endpoint: Optional["_models.ManagedInstancePrivateEndpointProperty"] = None, - private_link_service_connection_state: Optional["_models.ManagedInstancePrivateLinkServiceConnectionStateProperty"] = None, + private_link_service_connection_state: Optional[ + "_models.ManagedInstancePrivateLinkServiceConnectionStateProperty" + ] = None, **kwargs ): """ @@ -11369,13 +11472,13 @@ def __init__( :paramtype private_link_service_connection_state: ~azure.mgmt.sql.models.ManagedInstancePrivateLinkServiceConnectionStateProperty """ - super(ManagedInstancePrivateEndpointConnectionProperties, self).__init__(**kwargs) + super().__init__(**kwargs) self.private_endpoint = private_endpoint self.private_link_service_connection_state = private_link_service_connection_state self.provisioning_state = None -class ManagedInstancePrivateEndpointProperty(msrest.serialization.Model): +class ManagedInstancePrivateEndpointProperty(_serialization.Model): """ManagedInstancePrivateEndpointProperty. :ivar id: Resource id of the private endpoint. @@ -11383,20 +11486,15 @@ class ManagedInstancePrivateEndpointProperty(msrest.serialization.Model): """ _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, } - def __init__( - self, - *, - id: Optional[str] = None, - **kwargs - ): + def __init__(self, *, id: Optional[str] = None, **kwargs): # pylint: disable=redefined-builtin """ :keyword id: Resource id of the private endpoint. :paramtype id: str """ - super(ManagedInstancePrivateEndpointProperty, self).__init__(**kwargs) + super().__init__(**kwargs) self.id = id @@ -11416,30 +11514,26 @@ class ManagedInstancePrivateLink(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'properties': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "properties": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'properties': {'key': 'properties', 'type': 'ManagedInstancePrivateLinkProperties'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "properties": {"key": "properties", "type": "ManagedInstancePrivateLinkProperties"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedInstancePrivateLink, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.properties = None -class ManagedInstancePrivateLinkListResult(msrest.serialization.Model): +class ManagedInstancePrivateLinkListResult(_serialization.Model): """A list of private link resources. Variables are only populated by the server, and will be ignored when sending a request. @@ -11451,27 +11545,23 @@ class ManagedInstancePrivateLinkListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ManagedInstancePrivateLink]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ManagedInstancePrivateLink]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedInstancePrivateLinkListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ManagedInstancePrivateLinkProperties(msrest.serialization.Model): +class ManagedInstancePrivateLinkProperties(_serialization.Model): """Properties of a private link resource. Variables are only populated by the server, and will be ignored when sending a request. @@ -11483,67 +11573,57 @@ class ManagedInstancePrivateLinkProperties(msrest.serialization.Model): """ _validation = { - 'group_id': {'readonly': True}, - 'required_members': {'readonly': True}, + "group_id": {"readonly": True}, + "required_members": {"readonly": True}, } _attribute_map = { - 'group_id': {'key': 'groupId', 'type': 'str'}, - 'required_members': {'key': 'requiredMembers', 'type': '[str]'}, + "group_id": {"key": "groupId", "type": "str"}, + "required_members": {"key": "requiredMembers", "type": "[str]"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedInstancePrivateLinkProperties, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.group_id = None self.required_members = None -class ManagedInstancePrivateLinkServiceConnectionStateProperty(msrest.serialization.Model): +class ManagedInstancePrivateLinkServiceConnectionStateProperty(_serialization.Model): """ManagedInstancePrivateLinkServiceConnectionStateProperty. Variables are only populated by the server, and will be ignored when sending a request. All required parameters must be populated in order to send to Azure. - :ivar status: Required. The private link service connection status. + :ivar status: The private link service connection status. Required. :vartype status: str - :ivar description: Required. The private link service connection description. + :ivar description: The private link service connection description. Required. :vartype description: str :ivar actions_required: The private link service connection description. :vartype actions_required: str """ _validation = { - 'status': {'required': True}, - 'description': {'required': True}, - 'actions_required': {'readonly': True}, + "status": {"required": True}, + "description": {"required": True}, + "actions_required": {"readonly": True}, } _attribute_map = { - 'status': {'key': 'status', 'type': 'str'}, - 'description': {'key': 'description', 'type': 'str'}, - 'actions_required': {'key': 'actionsRequired', 'type': 'str'}, + "status": {"key": "status", "type": "str"}, + "description": {"key": "description", "type": "str"}, + "actions_required": {"key": "actionsRequired", "type": "str"}, } - def __init__( - self, - *, - status: str, - description: str, - **kwargs - ): + def __init__(self, *, status: str, description: str, **kwargs): """ - :keyword status: Required. The private link service connection status. + :keyword status: The private link service connection status. Required. :paramtype status: str - :keyword description: Required. The private link service connection description. + :keyword description: The private link service connection description. Required. :paramtype description: str """ - super(ManagedInstancePrivateLinkServiceConnectionStateProperty, self).__init__(**kwargs) + super().__init__(**kwargs) self.status = status self.description = description self.actions_required = None @@ -11565,33 +11645,28 @@ class ManagedInstanceQuery(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'query_text': {'key': 'properties.queryText', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "query_text": {"key": "properties.queryText", "type": "str"}, } - def __init__( - self, - *, - query_text: Optional[str] = None, - **kwargs - ): + def __init__(self, *, query_text: Optional[str] = None, **kwargs): """ :keyword query_text: Query text. :paramtype query_text: str """ - super(ManagedInstanceQuery, self).__init__(**kwargs) + super().__init__(**kwargs) self.query_text = query_text -class ManagedInstanceQueryStatistics(msrest.serialization.Model): +class ManagedInstanceQueryStatistics(_serialization.Model): """Execution statistics for one particular query. Variables are only populated by the server, and will be ignored when sending a request. @@ -11603,27 +11678,23 @@ class ManagedInstanceQueryStatistics(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[QueryStatistics]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[QueryStatistics]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedInstanceQueryStatistics, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ManagedInstanceUpdate(msrest.serialization.Model): +class ManagedInstanceUpdate(_serialization.Model): # pylint: disable=too-many-instance-attributes """An update request for an Azure SQL Database managed instance. Variables are only populated by the server, and will be ignored when sending a request. @@ -11632,20 +11703,20 @@ class ManagedInstanceUpdate(msrest.serialization.Model): :vartype sku: ~azure.mgmt.sql.models.Sku :ivar identity: Managed instance identity. :vartype identity: ~azure.mgmt.sql.models.ResourceIdentity - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar provisioning_state: Known values are: "Creating", "Deleting", "Updating", "Unknown", "Succeeded", "Failed", "Accepted", "Created", "Deleted", "Unrecognized", "Running", "Canceled", - "NotSpecified", "Registering", "TimedOut". + "NotSpecified", "Registering", and "TimedOut". :vartype provisioning_state: str or ~azure.mgmt.sql.models.ManagedInstancePropertiesProvisioningState :ivar managed_instance_create_mode: Specifies the mode of database creation. - + Default: Regular instance creation. - + Restore: Creates an instance by restoring a set of backups to specific point in time. - RestorePointInTime and SourceManagedInstanceId must be specified. Known values are: "Default", - "PointInTimeRestore". + RestorePointInTime and SourceManagedInstanceId must be specified. Known values are: "Default" + and "PointInTimeRestore". :vartype managed_instance_create_mode: str or ~azure.mgmt.sql.models.ManagedServerCreateMode :ivar fully_qualified_domain_name: The fully qualified domain name of the managed instance. :vartype fully_qualified_domain_name: str @@ -11661,7 +11732,7 @@ class ManagedInstanceUpdate(msrest.serialization.Model): :vartype state: str :ivar license_type: The license type. Possible values are 'LicenseIncluded' (regular price inclusive of a new SQL license) and 'BasePrice' (discounted AHB price for bringing your own SQL - licenses). Known values are: "LicenseIncluded", "BasePrice". + licenses). Known values are: "LicenseIncluded" and "BasePrice". :vartype license_type: str or ~azure.mgmt.sql.models.ManagedInstanceLicenseType :ivar v_cores: The number of vCores. Allowed values: 8, 16, 24, 32, 40, 64, 80. :vartype v_cores: int @@ -11684,7 +11755,7 @@ class ManagedInstanceUpdate(msrest.serialization.Model): database that will be restored to create the new database. :vartype restore_point_in_time: ~datetime.datetime :ivar proxy_override: Connection type used for connecting to the instance. Known values are: - "Proxy", "Redirect", "Default". + "Proxy", "Redirect", and "Default". :vartype proxy_override: str or ~azure.mgmt.sql.models.ManagedInstanceProxyOverride :ivar timezone_id: Id of the timezone. Allowed values are timezones supported by Windows. Windows keeps details on supported timezones, including the id, in registry under @@ -11707,13 +11778,13 @@ class ManagedInstanceUpdate(msrest.serialization.Model): :ivar current_backup_storage_redundancy: The storage account type used to store backups for this instance. The options are Local (LocallyRedundantStorage), Zone (ZoneRedundantStorage), Geo (GeoRedundantStorage) and GeoZone(GeoZoneRedundantStorage). Known values are: "Geo", - "Local", "Zone", "GeoZone". + "Local", "Zone", and "GeoZone". :vartype current_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy :ivar requested_backup_storage_redundancy: The storage account type to be used to store backups for this instance. The options are Local (LocallyRedundantStorage), Zone (ZoneRedundantStorage), Geo (GeoRedundantStorage) and GeoZone(GeoZoneRedundantStorage). Known - values are: "Geo", "Local", "Zone", "GeoZone". + values are: "Geo", "Local", "Zone", and "GeoZone". :vartype requested_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy :ivar zone_redundant: Whether or not the multi-az is enabled. @@ -11730,50 +11801,53 @@ class ManagedInstanceUpdate(msrest.serialization.Model): """ _validation = { - 'provisioning_state': {'readonly': True}, - 'fully_qualified_domain_name': {'readonly': True}, - 'state': {'readonly': True}, - 'dns_zone': {'readonly': True}, - 'private_endpoint_connections': {'readonly': True}, - 'current_backup_storage_redundancy': {'readonly': True}, - } - - _attribute_map = { - 'sku': {'key': 'sku', 'type': 'Sku'}, - 'identity': {'key': 'identity', 'type': 'ResourceIdentity'}, - 'tags': {'key': 'tags', 'type': '{str}'}, - 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, - 'managed_instance_create_mode': {'key': 'properties.managedInstanceCreateMode', 'type': 'str'}, - 'fully_qualified_domain_name': {'key': 'properties.fullyQualifiedDomainName', 'type': 'str'}, - 'administrator_login': {'key': 'properties.administratorLogin', 'type': 'str'}, - 'administrator_login_password': {'key': 'properties.administratorLoginPassword', 'type': 'str'}, - 'subnet_id': {'key': 'properties.subnetId', 'type': 'str'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'license_type': {'key': 'properties.licenseType', 'type': 'str'}, - 'v_cores': {'key': 'properties.vCores', 'type': 'int'}, - 'storage_size_in_gb': {'key': 'properties.storageSizeInGB', 'type': 'int'}, - 'collation': {'key': 'properties.collation', 'type': 'str'}, - 'dns_zone': {'key': 'properties.dnsZone', 'type': 'str'}, - 'dns_zone_partner': {'key': 'properties.dnsZonePartner', 'type': 'str'}, - 'public_data_endpoint_enabled': {'key': 'properties.publicDataEndpointEnabled', 'type': 'bool'}, - 'source_managed_instance_id': {'key': 'properties.sourceManagedInstanceId', 'type': 'str'}, - 'restore_point_in_time': {'key': 'properties.restorePointInTime', 'type': 'iso-8601'}, - 'proxy_override': {'key': 'properties.proxyOverride', 'type': 'str'}, - 'timezone_id': {'key': 'properties.timezoneId', 'type': 'str'}, - 'instance_pool_id': {'key': 'properties.instancePoolId', 'type': 'str'}, - 'maintenance_configuration_id': {'key': 'properties.maintenanceConfigurationId', 'type': 'str'}, - 'private_endpoint_connections': {'key': 'properties.privateEndpointConnections', 'type': '[ManagedInstancePecProperty]'}, - 'minimal_tls_version': {'key': 'properties.minimalTlsVersion', 'type': 'str'}, - 'current_backup_storage_redundancy': {'key': 'properties.currentBackupStorageRedundancy', 'type': 'str'}, - 'requested_backup_storage_redundancy': {'key': 'properties.requestedBackupStorageRedundancy', 'type': 'str'}, - 'zone_redundant': {'key': 'properties.zoneRedundant', 'type': 'bool'}, - 'primary_user_assigned_identity_id': {'key': 'properties.primaryUserAssignedIdentityId', 'type': 'str'}, - 'key_id': {'key': 'properties.keyId', 'type': 'str'}, - 'administrators': {'key': 'properties.administrators', 'type': 'ManagedInstanceExternalAdministrator'}, - 'service_principal': {'key': 'properties.servicePrincipal', 'type': 'ServicePrincipal'}, - } - - def __init__( + "provisioning_state": {"readonly": True}, + "fully_qualified_domain_name": {"readonly": True}, + "state": {"readonly": True}, + "dns_zone": {"readonly": True}, + "private_endpoint_connections": {"readonly": True}, + "current_backup_storage_redundancy": {"readonly": True}, + } + + _attribute_map = { + "sku": {"key": "sku", "type": "Sku"}, + "identity": {"key": "identity", "type": "ResourceIdentity"}, + "tags": {"key": "tags", "type": "{str}"}, + "provisioning_state": {"key": "properties.provisioningState", "type": "str"}, + "managed_instance_create_mode": {"key": "properties.managedInstanceCreateMode", "type": "str"}, + "fully_qualified_domain_name": {"key": "properties.fullyQualifiedDomainName", "type": "str"}, + "administrator_login": {"key": "properties.administratorLogin", "type": "str"}, + "administrator_login_password": {"key": "properties.administratorLoginPassword", "type": "str"}, + "subnet_id": {"key": "properties.subnetId", "type": "str"}, + "state": {"key": "properties.state", "type": "str"}, + "license_type": {"key": "properties.licenseType", "type": "str"}, + "v_cores": {"key": "properties.vCores", "type": "int"}, + "storage_size_in_gb": {"key": "properties.storageSizeInGB", "type": "int"}, + "collation": {"key": "properties.collation", "type": "str"}, + "dns_zone": {"key": "properties.dnsZone", "type": "str"}, + "dns_zone_partner": {"key": "properties.dnsZonePartner", "type": "str"}, + "public_data_endpoint_enabled": {"key": "properties.publicDataEndpointEnabled", "type": "bool"}, + "source_managed_instance_id": {"key": "properties.sourceManagedInstanceId", "type": "str"}, + "restore_point_in_time": {"key": "properties.restorePointInTime", "type": "iso-8601"}, + "proxy_override": {"key": "properties.proxyOverride", "type": "str"}, + "timezone_id": {"key": "properties.timezoneId", "type": "str"}, + "instance_pool_id": {"key": "properties.instancePoolId", "type": "str"}, + "maintenance_configuration_id": {"key": "properties.maintenanceConfigurationId", "type": "str"}, + "private_endpoint_connections": { + "key": "properties.privateEndpointConnections", + "type": "[ManagedInstancePecProperty]", + }, + "minimal_tls_version": {"key": "properties.minimalTlsVersion", "type": "str"}, + "current_backup_storage_redundancy": {"key": "properties.currentBackupStorageRedundancy", "type": "str"}, + "requested_backup_storage_redundancy": {"key": "properties.requestedBackupStorageRedundancy", "type": "str"}, + "zone_redundant": {"key": "properties.zoneRedundant", "type": "bool"}, + "primary_user_assigned_identity_id": {"key": "properties.primaryUserAssignedIdentityId", "type": "str"}, + "key_id": {"key": "properties.keyId", "type": "str"}, + "administrators": {"key": "properties.administrators", "type": "ManagedInstanceExternalAdministrator"}, + "service_principal": {"key": "properties.servicePrincipal", "type": "ServicePrincipal"}, + } + + def __init__( # pylint: disable=too-many-locals self, *, sku: Optional["_models.Sku"] = None, @@ -11809,15 +11883,15 @@ def __init__( :paramtype sku: ~azure.mgmt.sql.models.Sku :keyword identity: Managed instance identity. :paramtype identity: ~azure.mgmt.sql.models.ResourceIdentity - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] :keyword managed_instance_create_mode: Specifies the mode of database creation. - + Default: Regular instance creation. - + Restore: Creates an instance by restoring a set of backups to specific point in time. - RestorePointInTime and SourceManagedInstanceId must be specified. Known values are: "Default", - "PointInTimeRestore". + RestorePointInTime and SourceManagedInstanceId must be specified. Known values are: "Default" + and "PointInTimeRestore". :paramtype managed_instance_create_mode: str or ~azure.mgmt.sql.models.ManagedServerCreateMode :keyword administrator_login: Administrator username for the managed instance. Can only be specified when the managed instance is being created (and is required for creation). @@ -11829,7 +11903,7 @@ def __init__( :paramtype subnet_id: str :keyword license_type: The license type. Possible values are 'LicenseIncluded' (regular price inclusive of a new SQL license) and 'BasePrice' (discounted AHB price for bringing your own SQL - licenses). Known values are: "LicenseIncluded", "BasePrice". + licenses). Known values are: "LicenseIncluded" and "BasePrice". :paramtype license_type: str or ~azure.mgmt.sql.models.ManagedInstanceLicenseType :keyword v_cores: The number of vCores. Allowed values: 8, 16, 24, 32, 40, 64, 80. :paramtype v_cores: int @@ -11850,7 +11924,7 @@ def __init__( database that will be restored to create the new database. :paramtype restore_point_in_time: ~datetime.datetime :keyword proxy_override: Connection type used for connecting to the instance. Known values are: - "Proxy", "Redirect", "Default". + "Proxy", "Redirect", and "Default". :paramtype proxy_override: str or ~azure.mgmt.sql.models.ManagedInstanceProxyOverride :keyword timezone_id: Id of the timezone. Allowed values are timezones supported by Windows. Windows keeps details on supported timezones, including the id, in registry under @@ -11871,7 +11945,7 @@ def __init__( :keyword requested_backup_storage_redundancy: The storage account type to be used to store backups for this instance. The options are Local (LocallyRedundantStorage), Zone (ZoneRedundantStorage), Geo (GeoRedundantStorage) and GeoZone(GeoZoneRedundantStorage). Known - values are: "Geo", "Local", "Zone", "GeoZone". + values are: "Geo", "Local", "Zone", and "GeoZone". :paramtype requested_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy :keyword zone_redundant: Whether or not the multi-az is enabled. @@ -11886,7 +11960,7 @@ def __init__( :keyword service_principal: The managed instance's service principal. :paramtype service_principal: ~azure.mgmt.sql.models.ServicePrincipal """ - super(ManagedInstanceUpdate, self).__init__(**kwargs) + super().__init__(**kwargs) self.sku = sku self.identity = identity self.tags = tags @@ -11921,7 +11995,7 @@ def __init__( self.service_principal = service_principal -class ManagedInstanceVcoresCapability(msrest.serialization.Model): +class ManagedInstanceVcoresCapability(_serialization.Model): """The managed instance virtual cores capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -11944,46 +12018,44 @@ class ManagedInstanceVcoresCapability(msrest.serialization.Model): :vartype supported_maintenance_configurations: list[~azure.mgmt.sql.models.ManagedInstanceMaintenanceConfigurationCapability] :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'name': {'readonly': True}, - 'value': {'readonly': True}, - 'included_max_size': {'readonly': True}, - 'supported_storage_sizes': {'readonly': True}, - 'instance_pool_supported': {'readonly': True}, - 'standalone_supported': {'readonly': True}, - 'supported_maintenance_configurations': {'readonly': True}, - 'status': {'readonly': True}, + "name": {"readonly": True}, + "value": {"readonly": True}, + "included_max_size": {"readonly": True}, + "supported_storage_sizes": {"readonly": True}, + "instance_pool_supported": {"readonly": True}, + "standalone_supported": {"readonly": True}, + "supported_maintenance_configurations": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'value': {'key': 'value', 'type': 'int'}, - 'included_max_size': {'key': 'includedMaxSize', 'type': 'MaxSizeCapability'}, - 'supported_storage_sizes': {'key': 'supportedStorageSizes', 'type': '[MaxSizeRangeCapability]'}, - 'instance_pool_supported': {'key': 'instancePoolSupported', 'type': 'bool'}, - 'standalone_supported': {'key': 'standaloneSupported', 'type': 'bool'}, - 'supported_maintenance_configurations': {'key': 'supportedMaintenanceConfigurations', 'type': '[ManagedInstanceMaintenanceConfigurationCapability]'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "name": {"key": "name", "type": "str"}, + "value": {"key": "value", "type": "int"}, + "included_max_size": {"key": "includedMaxSize", "type": "MaxSizeCapability"}, + "supported_storage_sizes": {"key": "supportedStorageSizes", "type": "[MaxSizeRangeCapability]"}, + "instance_pool_supported": {"key": "instancePoolSupported", "type": "bool"}, + "standalone_supported": {"key": "standaloneSupported", "type": "bool"}, + "supported_maintenance_configurations": { + "key": "supportedMaintenanceConfigurations", + "type": "[ManagedInstanceMaintenanceConfigurationCapability]", + }, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(ManagedInstanceVcoresCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.name = None self.value = None self.included_max_size = None @@ -11995,7 +12067,7 @@ def __init__( self.reason = reason -class ManagedInstanceVersionCapability(msrest.serialization.Model): +class ManagedInstanceVersionCapability(_serialization.Model): """The managed instance capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -12008,38 +12080,36 @@ class ManagedInstanceVersionCapability(msrest.serialization.Model): :vartype supported_instance_pool_editions: list[~azure.mgmt.sql.models.InstancePoolEditionCapability] :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'name': {'readonly': True}, - 'supported_editions': {'readonly': True}, - 'supported_instance_pool_editions': {'readonly': True}, - 'status': {'readonly': True}, + "name": {"readonly": True}, + "supported_editions": {"readonly": True}, + "supported_instance_pool_editions": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'supported_editions': {'key': 'supportedEditions', 'type': '[ManagedInstanceEditionCapability]'}, - 'supported_instance_pool_editions': {'key': 'supportedInstancePoolEditions', 'type': '[InstancePoolEditionCapability]'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "name": {"key": "name", "type": "str"}, + "supported_editions": {"key": "supportedEditions", "type": "[ManagedInstanceEditionCapability]"}, + "supported_instance_pool_editions": { + "key": "supportedInstancePoolEditions", + "type": "[InstancePoolEditionCapability]", + }, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(ManagedInstanceVersionCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.name = None self.supported_editions = None self.supported_instance_pool_editions = None @@ -12077,19 +12147,22 @@ class ManagedInstanceVulnerabilityAssessment(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'storage_container_path': {'key': 'properties.storageContainerPath', 'type': 'str'}, - 'storage_container_sas_key': {'key': 'properties.storageContainerSasKey', 'type': 'str'}, - 'storage_account_access_key': {'key': 'properties.storageAccountAccessKey', 'type': 'str'}, - 'recurring_scans': {'key': 'properties.recurringScans', 'type': 'VulnerabilityAssessmentRecurringScansProperties'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "storage_container_path": {"key": "properties.storageContainerPath", "type": "str"}, + "storage_container_sas_key": {"key": "properties.storageContainerSasKey", "type": "str"}, + "storage_account_access_key": {"key": "properties.storageAccountAccessKey", "type": "str"}, + "recurring_scans": { + "key": "properties.recurringScans", + "type": "VulnerabilityAssessmentRecurringScansProperties", + }, } def __init__( @@ -12119,14 +12192,14 @@ def __init__( :paramtype recurring_scans: ~azure.mgmt.sql.models.VulnerabilityAssessmentRecurringScansProperties """ - super(ManagedInstanceVulnerabilityAssessment, self).__init__(**kwargs) + super().__init__(**kwargs) self.storage_container_path = storage_container_path self.storage_container_sas_key = storage_container_sas_key self.storage_account_access_key = storage_account_access_key self.recurring_scans = recurring_scans -class ManagedInstanceVulnerabilityAssessmentListResult(msrest.serialization.Model): +class ManagedInstanceVulnerabilityAssessmentListResult(_serialization.Model): """A list of the ManagedInstance's vulnerability assessments. Variables are only populated by the server, and will be ignored when sending a request. @@ -12138,22 +12211,18 @@ class ManagedInstanceVulnerabilityAssessmentListResult(msrest.serialization.Mode """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ManagedInstanceVulnerabilityAssessment]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ManagedInstanceVulnerabilityAssessment]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedInstanceVulnerabilityAssessmentListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -12176,66 +12245,57 @@ class ManagedServerDnsAlias(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'azure_dns_record': {'readonly': True}, - 'public_azure_dns_record': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "azure_dns_record": {"readonly": True}, + "public_azure_dns_record": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'azure_dns_record': {'key': 'properties.azureDnsRecord', 'type': 'str'}, - 'public_azure_dns_record': {'key': 'properties.publicAzureDnsRecord', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "azure_dns_record": {"key": "properties.azureDnsRecord", "type": "str"}, + "public_azure_dns_record": {"key": "properties.publicAzureDnsRecord", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedServerDnsAlias, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.azure_dns_record = None self.public_azure_dns_record = None -class ManagedServerDnsAliasAcquisition(msrest.serialization.Model): +class ManagedServerDnsAliasAcquisition(_serialization.Model): """A managed server DNS alias acquisition request. All required parameters must be populated in order to send to Azure. - :ivar old_managed_server_dns_alias_resource_id: Required. The resource ID of the managed server - DNS alias that will be acquired to point to this managed server instead. + :ivar old_managed_server_dns_alias_resource_id: The resource ID of the managed server DNS alias + that will be acquired to point to this managed server instead. Required. :vartype old_managed_server_dns_alias_resource_id: str """ _validation = { - 'old_managed_server_dns_alias_resource_id': {'required': True}, + "old_managed_server_dns_alias_resource_id": {"required": True}, } _attribute_map = { - 'old_managed_server_dns_alias_resource_id': {'key': 'oldManagedServerDnsAliasResourceId', 'type': 'str'}, + "old_managed_server_dns_alias_resource_id": {"key": "oldManagedServerDnsAliasResourceId", "type": "str"}, } - def __init__( - self, - *, - old_managed_server_dns_alias_resource_id: str, - **kwargs - ): + def __init__(self, *, old_managed_server_dns_alias_resource_id: str, **kwargs): """ - :keyword old_managed_server_dns_alias_resource_id: Required. The resource ID of the managed - server DNS alias that will be acquired to point to this managed server instead. + :keyword old_managed_server_dns_alias_resource_id: The resource ID of the managed server DNS + alias that will be acquired to point to this managed server instead. Required. :paramtype old_managed_server_dns_alias_resource_id: str """ - super(ManagedServerDnsAliasAcquisition, self).__init__(**kwargs) + super().__init__(**kwargs) self.old_managed_server_dns_alias_resource_id = old_managed_server_dns_alias_resource_id -class ManagedServerDnsAliasCreation(msrest.serialization.Model): +class ManagedServerDnsAliasCreation(_serialization.Model): """A managed server dns alias creation request. :ivar create_dns_record: Whether or not DNS record should be created for this alias. @@ -12243,24 +12303,19 @@ class ManagedServerDnsAliasCreation(msrest.serialization.Model): """ _attribute_map = { - 'create_dns_record': {'key': 'createDnsRecord', 'type': 'bool'}, + "create_dns_record": {"key": "createDnsRecord", "type": "bool"}, } - def __init__( - self, - *, - create_dns_record: Optional[bool] = True, - **kwargs - ): + def __init__(self, *, create_dns_record: bool = True, **kwargs): """ :keyword create_dns_record: Whether or not DNS record should be created for this alias. :paramtype create_dns_record: bool """ - super(ManagedServerDnsAliasCreation, self).__init__(**kwargs) + super().__init__(**kwargs) self.create_dns_record = create_dns_record -class ManagedServerDnsAliasListResult(msrest.serialization.Model): +class ManagedServerDnsAliasListResult(_serialization.Model): """A list of managed server DNS aliases. Variables are only populated by the server, and will be ignored when sending a request. @@ -12272,27 +12327,23 @@ class ManagedServerDnsAliasListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ManagedServerDnsAlias]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ManagedServerDnsAlias]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedServerDnsAliasListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ManagedServerSecurityAlertPolicy(ProxyResource): +class ManagedServerSecurityAlertPolicy(ProxyResource): # pylint: disable=too-many-instance-attributes """A managed server security alert policy. Variables are only populated by the server, and will be ignored when sending a request. @@ -12306,7 +12357,7 @@ class ManagedServerSecurityAlertPolicy(ProxyResource): :ivar system_data: SystemData of SecurityAlertPolicyResource. :vartype system_data: ~azure.mgmt.sql.models.SystemData :ivar state: Specifies the state of the policy, whether it is enabled or disabled or a policy - has not been applied yet on the specific database. Known values are: "Enabled", "Disabled". + has not been applied yet on the specific database. Known values are: "Enabled" and "Disabled". :vartype state: str or ~azure.mgmt.sql.models.SecurityAlertsPolicyState :ivar disabled_alerts: Specifies an array of alerts that are disabled. Allowed values are: Sql_Injection, Sql_Injection_Vulnerability, Access_Anomaly, Data_Exfiltration, Unsafe_Action, @@ -12330,26 +12381,26 @@ class ManagedServerSecurityAlertPolicy(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'system_data': {'readonly': True}, - 'creation_time': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "system_data": {"readonly": True}, + "creation_time": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'system_data': {'key': 'systemData', 'type': 'SystemData'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'disabled_alerts': {'key': 'properties.disabledAlerts', 'type': '[str]'}, - 'email_addresses': {'key': 'properties.emailAddresses', 'type': '[str]'}, - 'email_account_admins': {'key': 'properties.emailAccountAdmins', 'type': 'bool'}, - 'storage_endpoint': {'key': 'properties.storageEndpoint', 'type': 'str'}, - 'storage_account_access_key': {'key': 'properties.storageAccountAccessKey', 'type': 'str'}, - 'retention_days': {'key': 'properties.retentionDays', 'type': 'int'}, - 'creation_time': {'key': 'properties.creationTime', 'type': 'iso-8601'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "system_data": {"key": "systemData", "type": "SystemData"}, + "state": {"key": "properties.state", "type": "str"}, + "disabled_alerts": {"key": "properties.disabledAlerts", "type": "[str]"}, + "email_addresses": {"key": "properties.emailAddresses", "type": "[str]"}, + "email_account_admins": {"key": "properties.emailAccountAdmins", "type": "bool"}, + "storage_endpoint": {"key": "properties.storageEndpoint", "type": "str"}, + "storage_account_access_key": {"key": "properties.storageAccountAccessKey", "type": "str"}, + "retention_days": {"key": "properties.retentionDays", "type": "int"}, + "creation_time": {"key": "properties.creationTime", "type": "iso-8601"}, } def __init__( @@ -12366,7 +12417,7 @@ def __init__( ): """ :keyword state: Specifies the state of the policy, whether it is enabled or disabled or a - policy has not been applied yet on the specific database. Known values are: "Enabled", + policy has not been applied yet on the specific database. Known values are: "Enabled" and "Disabled". :paramtype state: str or ~azure.mgmt.sql.models.SecurityAlertsPolicyState :keyword disabled_alerts: Specifies an array of alerts that are disabled. Allowed values are: @@ -12388,7 +12439,7 @@ def __init__( logs. :paramtype retention_days: int """ - super(ManagedServerSecurityAlertPolicy, self).__init__(**kwargs) + super().__init__(**kwargs) self.system_data = None self.state = state self.disabled_alerts = disabled_alerts @@ -12400,7 +12451,7 @@ def __init__( self.creation_time = None -class ManagedServerSecurityAlertPolicyListResult(msrest.serialization.Model): +class ManagedServerSecurityAlertPolicyListResult(_serialization.Model): """A list of the managed Server's security alert policies. Variables are only populated by the server, and will be ignored when sending a request. @@ -12412,22 +12463,18 @@ class ManagedServerSecurityAlertPolicyListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ManagedServerSecurityAlertPolicy]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ManagedServerSecurityAlertPolicy]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedServerSecurityAlertPolicyListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -12444,39 +12491,34 @@ class ManagedTransparentDataEncryption(ProxyResource): :ivar type: Resource type. :vartype type: str :ivar state: Specifies the state of the transparent data encryption. Known values are: - "Enabled", "Disabled". + "Enabled" and "Disabled". :vartype state: str or ~azure.mgmt.sql.models.TransparentDataEncryptionState """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'state': {'key': 'properties.state', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "state": {"key": "properties.state", "type": "str"}, } - def __init__( - self, - *, - state: Optional[Union[str, "_models.TransparentDataEncryptionState"]] = None, - **kwargs - ): + def __init__(self, *, state: Optional[Union[str, "_models.TransparentDataEncryptionState"]] = None, **kwargs): """ :keyword state: Specifies the state of the transparent data encryption. Known values are: - "Enabled", "Disabled". + "Enabled" and "Disabled". :paramtype state: str or ~azure.mgmt.sql.models.TransparentDataEncryptionState """ - super(ManagedTransparentDataEncryption, self).__init__(**kwargs) + super().__init__(**kwargs) self.state = state -class ManagedTransparentDataEncryptionListResult(msrest.serialization.Model): +class ManagedTransparentDataEncryptionListResult(_serialization.Model): """A list of managed transparent data encryptions. Variables are only populated by the server, and will be ignored when sending a request. @@ -12488,27 +12530,23 @@ class ManagedTransparentDataEncryptionListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ManagedTransparentDataEncryption]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ManagedTransparentDataEncryption]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ManagedTransparentDataEncryptionListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class MaxSizeCapability(msrest.serialization.Model): +class MaxSizeCapability(_serialization.Model): """The maximum size capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -12516,32 +12554,28 @@ class MaxSizeCapability(msrest.serialization.Model): :ivar limit: The maximum size limit (see 'unit' for the units). :vartype limit: int :ivar unit: The units that the limit is expressed in. Known values are: "Megabytes", - "Gigabytes", "Terabytes", "Petabytes". + "Gigabytes", "Terabytes", and "Petabytes". :vartype unit: str or ~azure.mgmt.sql.models.MaxSizeUnit """ _validation = { - 'limit': {'readonly': True}, - 'unit': {'readonly': True}, + "limit": {"readonly": True}, + "unit": {"readonly": True}, } _attribute_map = { - 'limit': {'key': 'limit', 'type': 'int'}, - 'unit': {'key': 'unit', 'type': 'str'}, + "limit": {"key": "limit", "type": "int"}, + "unit": {"key": "unit", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(MaxSizeCapability, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.limit = None self.unit = None -class MaxSizeRangeCapability(msrest.serialization.Model): +class MaxSizeRangeCapability(_serialization.Model): """The maximum size range capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -12556,40 +12590,35 @@ class MaxSizeRangeCapability(msrest.serialization.Model): :ivar log_size: Size of transaction log. :vartype log_size: ~azure.mgmt.sql.models.LogSizeCapability :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'min_value': {'readonly': True}, - 'max_value': {'readonly': True}, - 'scale_size': {'readonly': True}, - 'log_size': {'readonly': True}, - 'status': {'readonly': True}, + "min_value": {"readonly": True}, + "max_value": {"readonly": True}, + "scale_size": {"readonly": True}, + "log_size": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'min_value': {'key': 'minValue', 'type': 'MaxSizeCapability'}, - 'max_value': {'key': 'maxValue', 'type': 'MaxSizeCapability'}, - 'scale_size': {'key': 'scaleSize', 'type': 'MaxSizeCapability'}, - 'log_size': {'key': 'logSize', 'type': 'LogSizeCapability'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "min_value": {"key": "minValue", "type": "MaxSizeCapability"}, + "max_value": {"key": "maxValue", "type": "MaxSizeCapability"}, + "scale_size": {"key": "scaleSize", "type": "MaxSizeCapability"}, + "log_size": {"key": "logSize", "type": "LogSizeCapability"}, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(MaxSizeRangeCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.min_value = None self.max_value = None self.scale_size = None @@ -12598,7 +12627,7 @@ def __init__( self.reason = reason -class Metric(msrest.serialization.Model): +class Metric(_serialization.Model): """Database metrics. Variables are only populated by the server, and will be ignored when sending a request. @@ -12610,7 +12639,7 @@ class Metric(msrest.serialization.Model): :ivar time_grain: The time step to be used to summarize the metric values. :vartype time_grain: str :ivar unit: The unit of the metric. Known values are: "count", "bytes", "seconds", "percent", - "countPerSecond", "bytesPerSecond". + "countPerSecond", and "bytesPerSecond". :vartype unit: str or ~azure.mgmt.sql.models.UnitType :ivar name: The name information for the metric. :vartype name: ~azure.mgmt.sql.models.MetricName @@ -12619,30 +12648,26 @@ class Metric(msrest.serialization.Model): """ _validation = { - 'start_time': {'readonly': True}, - 'end_time': {'readonly': True}, - 'time_grain': {'readonly': True}, - 'unit': {'readonly': True}, - 'name': {'readonly': True}, - 'metric_values': {'readonly': True}, + "start_time": {"readonly": True}, + "end_time": {"readonly": True}, + "time_grain": {"readonly": True}, + "unit": {"readonly": True}, + "name": {"readonly": True}, + "metric_values": {"readonly": True}, } _attribute_map = { - 'start_time': {'key': 'startTime', 'type': 'iso-8601'}, - 'end_time': {'key': 'endTime', 'type': 'iso-8601'}, - 'time_grain': {'key': 'timeGrain', 'type': 'str'}, - 'unit': {'key': 'unit', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'MetricName'}, - 'metric_values': {'key': 'metricValues', 'type': '[MetricValue]'}, + "start_time": {"key": "startTime", "type": "iso-8601"}, + "end_time": {"key": "endTime", "type": "iso-8601"}, + "time_grain": {"key": "timeGrain", "type": "str"}, + "unit": {"key": "unit", "type": "str"}, + "name": {"key": "name", "type": "MetricName"}, + "metric_values": {"key": "metricValues", "type": "[MetricValue]"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(Metric, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.start_time = None self.end_time = None self.time_grain = None @@ -12651,7 +12676,7 @@ def __init__( self.metric_values = None -class MetricAvailability(msrest.serialization.Model): +class MetricAvailability(_serialization.Model): """A metric availability value. Variables are only populated by the server, and will be ignored when sending a request. @@ -12663,27 +12688,23 @@ class MetricAvailability(msrest.serialization.Model): """ _validation = { - 'retention': {'readonly': True}, - 'time_grain': {'readonly': True}, + "retention": {"readonly": True}, + "time_grain": {"readonly": True}, } _attribute_map = { - 'retention': {'key': 'retention', 'type': 'str'}, - 'time_grain': {'key': 'timeGrain', 'type': 'str'}, + "retention": {"key": "retention", "type": "str"}, + "time_grain": {"key": "timeGrain", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(MetricAvailability, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.retention = None self.time_grain = None -class MetricDefinition(msrest.serialization.Model): +class MetricDefinition(_serialization.Model): """A database metric definition. Variables are only populated by the server, and will be ignored when sending a request. @@ -12691,40 +12712,36 @@ class MetricDefinition(msrest.serialization.Model): :ivar name: The name information for the metric. :vartype name: ~azure.mgmt.sql.models.MetricName :ivar primary_aggregation_type: The primary aggregation type defining how metric values are - displayed. Known values are: "None", "Average", "Count", "Minimum", "Maximum", "Total". + displayed. Known values are: "None", "Average", "Count", "Minimum", "Maximum", and "Total". :vartype primary_aggregation_type: str or ~azure.mgmt.sql.models.PrimaryAggregationType :ivar resource_uri: The resource uri of the database. :vartype resource_uri: str :ivar unit: The unit of the metric. Known values are: "Count", "Bytes", "Seconds", "Percent", - "CountPerSecond", "BytesPerSecond". + "CountPerSecond", and "BytesPerSecond". :vartype unit: str or ~azure.mgmt.sql.models.UnitDefinitionType :ivar metric_availabilities: The list of database metric availabilities for the metric. :vartype metric_availabilities: list[~azure.mgmt.sql.models.MetricAvailability] """ _validation = { - 'name': {'readonly': True}, - 'primary_aggregation_type': {'readonly': True}, - 'resource_uri': {'readonly': True}, - 'unit': {'readonly': True}, - 'metric_availabilities': {'readonly': True}, + "name": {"readonly": True}, + "primary_aggregation_type": {"readonly": True}, + "resource_uri": {"readonly": True}, + "unit": {"readonly": True}, + "metric_availabilities": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'MetricName'}, - 'primary_aggregation_type': {'key': 'primaryAggregationType', 'type': 'str'}, - 'resource_uri': {'key': 'resourceUri', 'type': 'str'}, - 'unit': {'key': 'unit', 'type': 'str'}, - 'metric_availabilities': {'key': 'metricAvailabilities', 'type': '[MetricAvailability]'}, + "name": {"key": "name", "type": "MetricName"}, + "primary_aggregation_type": {"key": "primaryAggregationType", "type": "str"}, + "resource_uri": {"key": "resourceUri", "type": "str"}, + "unit": {"key": "unit", "type": "str"}, + "metric_availabilities": {"key": "metricAvailabilities", "type": "[MetricAvailability]"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(MetricDefinition, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.name = None self.primary_aggregation_type = None self.resource_uri = None @@ -12732,69 +12749,59 @@ def __init__( self.metric_availabilities = None -class MetricDefinitionListResult(msrest.serialization.Model): +class MetricDefinitionListResult(_serialization.Model): """The response to a list database metric definitions request. All required parameters must be populated in order to send to Azure. - :ivar value: Required. The list of metric definitions for the database. + :ivar value: The list of metric definitions for the database. Required. :vartype value: list[~azure.mgmt.sql.models.MetricDefinition] """ _validation = { - 'value': {'required': True}, + "value": {"required": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[MetricDefinition]'}, + "value": {"key": "value", "type": "[MetricDefinition]"}, } - def __init__( - self, - *, - value: List["_models.MetricDefinition"], - **kwargs - ): + def __init__(self, *, value: List["_models.MetricDefinition"], **kwargs): """ - :keyword value: Required. The list of metric definitions for the database. + :keyword value: The list of metric definitions for the database. Required. :paramtype value: list[~azure.mgmt.sql.models.MetricDefinition] """ - super(MetricDefinitionListResult, self).__init__(**kwargs) + super().__init__(**kwargs) self.value = value -class MetricListResult(msrest.serialization.Model): +class MetricListResult(_serialization.Model): """The response to a list database metrics request. All required parameters must be populated in order to send to Azure. - :ivar value: Required. The list of metrics for the database. + :ivar value: The list of metrics for the database. Required. :vartype value: list[~azure.mgmt.sql.models.Metric] """ _validation = { - 'value': {'required': True}, + "value": {"required": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[Metric]'}, + "value": {"key": "value", "type": "[Metric]"}, } - def __init__( - self, - *, - value: List["_models.Metric"], - **kwargs - ): + def __init__(self, *, value: List["_models.Metric"], **kwargs): """ - :keyword value: Required. The list of metrics for the database. + :keyword value: The list of metrics for the database. Required. :paramtype value: list[~azure.mgmt.sql.models.Metric] """ - super(MetricListResult, self).__init__(**kwargs) + super().__init__(**kwargs) self.value = value -class MetricName(msrest.serialization.Model): +class MetricName(_serialization.Model): """A database metric name. Variables are only populated by the server, and will be ignored when sending a request. @@ -12806,27 +12813,23 @@ class MetricName(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'localized_value': {'readonly': True}, + "value": {"readonly": True}, + "localized_value": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': 'str'}, - 'localized_value': {'key': 'localizedValue', 'type': 'str'}, + "value": {"key": "value", "type": "str"}, + "localized_value": {"key": "localizedValue", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(MetricName, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.localized_value = None -class MetricValue(msrest.serialization.Model): +class MetricValue(_serialization.Model): """Represents database metrics. Variables are only populated by the server, and will be ignored when sending a request. @@ -12846,30 +12849,26 @@ class MetricValue(msrest.serialization.Model): """ _validation = { - 'count': {'readonly': True}, - 'average': {'readonly': True}, - 'maximum': {'readonly': True}, - 'minimum': {'readonly': True}, - 'timestamp': {'readonly': True}, - 'total': {'readonly': True}, + "count": {"readonly": True}, + "average": {"readonly": True}, + "maximum": {"readonly": True}, + "minimum": {"readonly": True}, + "timestamp": {"readonly": True}, + "total": {"readonly": True}, } _attribute_map = { - 'count': {'key': 'count', 'type': 'int'}, - 'average': {'key': 'average', 'type': 'float'}, - 'maximum': {'key': 'maximum', 'type': 'float'}, - 'minimum': {'key': 'minimum', 'type': 'float'}, - 'timestamp': {'key': 'timestamp', 'type': 'iso-8601'}, - 'total': {'key': 'total', 'type': 'float'}, + "count": {"key": "count", "type": "int"}, + "average": {"key": "average", "type": "float"}, + "maximum": {"key": "maximum", "type": "float"}, + "minimum": {"key": "minimum", "type": "float"}, + "timestamp": {"key": "timestamp", "type": "iso-8601"}, + "total": {"key": "total", "type": "float"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(MetricValue, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.count = None self.average = None self.maximum = None @@ -12878,7 +12877,7 @@ def __init__( self.total = None -class MinCapacityCapability(msrest.serialization.Model): +class MinCapacityCapability(_serialization.Model): """The min capacity capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -12886,40 +12885,35 @@ class MinCapacityCapability(msrest.serialization.Model): :ivar value: Min capacity value. :vartype value: float :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'value': {'readonly': True}, - 'status': {'readonly': True}, + "value": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': 'float'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "value": {"key": "value", "type": "float"}, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(MinCapacityCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.value = None self.status = None self.reason = reason -class Name(msrest.serialization.Model): +class Name(_serialization.Model): """ARM Usage Name. :ivar value: Usage name value. @@ -12929,29 +12923,23 @@ class Name(msrest.serialization.Model): """ _attribute_map = { - 'value': {'key': 'value', 'type': 'str'}, - 'localized_value': {'key': 'localizedValue', 'type': 'str'}, + "value": {"key": "value", "type": "str"}, + "localized_value": {"key": "localizedValue", "type": "str"}, } - def __init__( - self, - *, - value: Optional[str] = None, - localized_value: Optional[str] = None, - **kwargs - ): + def __init__(self, *, value: Optional[str] = None, localized_value: Optional[str] = None, **kwargs): """ :keyword value: Usage name value. :paramtype value: str :keyword localized_value: Usage name localized value. :paramtype localized_value: str """ - super(Name, self).__init__(**kwargs) + super().__init__(**kwargs) self.value = value self.localized_value = localized_value -class NetworkIsolationSettings(msrest.serialization.Model): +class NetworkIsolationSettings(_serialization.Model): """Contains the ARM resources for which to create private endpoint connection. :ivar storage_account_resource_id: The resource id for the storage account used to store BACPAC @@ -12965,8 +12953,8 @@ class NetworkIsolationSettings(msrest.serialization.Model): """ _attribute_map = { - 'storage_account_resource_id': {'key': 'storageAccountResourceId', 'type': 'str'}, - 'sql_server_resource_id': {'key': 'sqlServerResourceId', 'type': 'str'}, + "storage_account_resource_id": {"key": "storageAccountResourceId", "type": "str"}, + "sql_server_resource_id": {"key": "sqlServerResourceId", "type": "str"}, } def __init__( @@ -12986,12 +12974,12 @@ def __init__( server which is target of the operation. :paramtype sql_server_resource_id: str """ - super(NetworkIsolationSettings, self).__init__(**kwargs) + super().__init__(**kwargs) self.storage_account_resource_id = storage_account_resource_id self.sql_server_resource_id = sql_server_resource_id -class Operation(msrest.serialization.Model): +class Operation(_serialization.Model): """SQL REST API operation definition. Variables are only populated by the server, and will be ignored when sending a request. @@ -13000,40 +12988,36 @@ class Operation(msrest.serialization.Model): :vartype name: str :ivar display: The localized display information for this particular operation / action. :vartype display: ~azure.mgmt.sql.models.OperationDisplay - :ivar origin: The intended executor of the operation. Known values are: "user", "system". + :ivar origin: The intended executor of the operation. Known values are: "user" and "system". :vartype origin: str or ~azure.mgmt.sql.models.OperationOrigin :ivar properties: Additional descriptions for the operation. - :vartype properties: dict[str, any] + :vartype properties: dict[str, JSON] """ _validation = { - 'name': {'readonly': True}, - 'display': {'readonly': True}, - 'origin': {'readonly': True}, - 'properties': {'readonly': True}, + "name": {"readonly": True}, + "display": {"readonly": True}, + "origin": {"readonly": True}, + "properties": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'display': {'key': 'display', 'type': 'OperationDisplay'}, - 'origin': {'key': 'origin', 'type': 'str'}, - 'properties': {'key': 'properties', 'type': '{object}'}, + "name": {"key": "name", "type": "str"}, + "display": {"key": "display", "type": "OperationDisplay"}, + "origin": {"key": "origin", "type": "str"}, + "properties": {"key": "properties", "type": "{object}"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(Operation, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.name = None self.display = None self.origin = None self.properties = None -class OperationDisplay(msrest.serialization.Model): +class OperationDisplay(_serialization.Model): """Display metadata associated with the operation. Variables are only populated by the server, and will be ignored when sending a request. @@ -13050,33 +13034,29 @@ class OperationDisplay(msrest.serialization.Model): """ _validation = { - 'provider': {'readonly': True}, - 'resource': {'readonly': True}, - 'operation': {'readonly': True}, - 'description': {'readonly': True}, + "provider": {"readonly": True}, + "resource": {"readonly": True}, + "operation": {"readonly": True}, + "description": {"readonly": True}, } _attribute_map = { - 'provider': {'key': 'provider', 'type': 'str'}, - 'resource': {'key': 'resource', 'type': 'str'}, - 'operation': {'key': 'operation', 'type': 'str'}, - 'description': {'key': 'description', 'type': 'str'}, + "provider": {"key": "provider", "type": "str"}, + "resource": {"key": "resource", "type": "str"}, + "operation": {"key": "operation", "type": "str"}, + "description": {"key": "description", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(OperationDisplay, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.provider = None self.resource = None self.operation = None self.description = None -class OperationImpact(msrest.serialization.Model): +class OperationImpact(_serialization.Model): """The impact of an operation, both in absolute and relative terms. Variables are only populated by the server, and will be ignored when sending a request. @@ -13092,33 +13072,29 @@ class OperationImpact(msrest.serialization.Model): """ _validation = { - 'name': {'readonly': True}, - 'unit': {'readonly': True}, - 'change_value_absolute': {'readonly': True}, - 'change_value_relative': {'readonly': True}, + "name": {"readonly": True}, + "unit": {"readonly": True}, + "change_value_absolute": {"readonly": True}, + "change_value_relative": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'unit': {'key': 'unit', 'type': 'str'}, - 'change_value_absolute': {'key': 'changeValueAbsolute', 'type': 'float'}, - 'change_value_relative': {'key': 'changeValueRelative', 'type': 'float'}, + "name": {"key": "name", "type": "str"}, + "unit": {"key": "unit", "type": "str"}, + "change_value_absolute": {"key": "changeValueAbsolute", "type": "float"}, + "change_value_relative": {"key": "changeValueRelative", "type": "float"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(OperationImpact, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.name = None self.unit = None self.change_value_absolute = None self.change_value_relative = None -class OperationListResult(msrest.serialization.Model): +class OperationListResult(_serialization.Model): """Result of the request to list SQL operations. Variables are only populated by the server, and will be ignored when sending a request. @@ -13130,22 +13106,18 @@ class OperationListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[Operation]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[Operation]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(OperationListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -13166,30 +13138,26 @@ class OutboundFirewallRule(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'provisioning_state': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "provisioning_state": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "provisioning_state": {"key": "properties.provisioningState", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(OutboundFirewallRule, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.provisioning_state = None -class OutboundFirewallRuleListResult(msrest.serialization.Model): +class OutboundFirewallRuleListResult(_serialization.Model): """A list of outbound rules. Variables are only populated by the server, and will be ignored when sending a request. @@ -13201,71 +13169,62 @@ class OutboundFirewallRuleListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[OutboundFirewallRule]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[OutboundFirewallRule]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(OutboundFirewallRuleListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class PartnerInfo(msrest.serialization.Model): +class PartnerInfo(_serialization.Model): """Partner server information for the failover group. Variables are only populated by the server, and will be ignored when sending a request. All required parameters must be populated in order to send to Azure. - :ivar id: Required. Resource identifier of the partner server. + :ivar id: Resource identifier of the partner server. Required. :vartype id: str :ivar location: Geo location of the partner server. :vartype location: str - :ivar replication_role: Replication role of the partner server. Known values are: "Primary", + :ivar replication_role: Replication role of the partner server. Known values are: "Primary" and "Secondary". :vartype replication_role: str or ~azure.mgmt.sql.models.FailoverGroupReplicationRole """ _validation = { - 'id': {'required': True}, - 'location': {'readonly': True}, - 'replication_role': {'readonly': True}, + "id": {"required": True}, + "location": {"readonly": True}, + "replication_role": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'replication_role': {'key': 'replicationRole', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "replication_role": {"key": "replicationRole", "type": "str"}, } - def __init__( - self, - *, - id: str, - **kwargs - ): + def __init__(self, *, id: str, **kwargs): # pylint: disable=redefined-builtin """ - :keyword id: Required. Resource identifier of the partner server. + :keyword id: Resource identifier of the partner server. Required. :paramtype id: str """ - super(PartnerInfo, self).__init__(**kwargs) + super().__init__(**kwargs) self.id = id self.location = None self.replication_role = None -class PartnerRegionInfo(msrest.serialization.Model): +class PartnerRegionInfo(_serialization.Model): """Partner region information for the failover group. Variables are only populated by the server, and will be ignored when sending a request. @@ -13273,62 +13232,53 @@ class PartnerRegionInfo(msrest.serialization.Model): :ivar location: Geo location of the partner managed instances. :vartype location: str :ivar replication_role: Replication role of the partner managed instances. Known values are: - "Primary", "Secondary". + "Primary" and "Secondary". :vartype replication_role: str or ~azure.mgmt.sql.models.InstanceFailoverGroupReplicationRole """ _validation = { - 'replication_role': {'readonly': True}, + "replication_role": {"readonly": True}, } _attribute_map = { - 'location': {'key': 'location', 'type': 'str'}, - 'replication_role': {'key': 'replicationRole', 'type': 'str'}, + "location": {"key": "location", "type": "str"}, + "replication_role": {"key": "replicationRole", "type": "str"}, } - def __init__( - self, - *, - location: Optional[str] = None, - **kwargs - ): + def __init__(self, *, location: Optional[str] = None, **kwargs): """ :keyword location: Geo location of the partner managed instances. :paramtype location: str """ - super(PartnerRegionInfo, self).__init__(**kwargs) + super().__init__(**kwargs) self.location = location self.replication_role = None -class PerformanceLevelCapability(msrest.serialization.Model): +class PerformanceLevelCapability(_serialization.Model): """The performance level capability. Variables are only populated by the server, and will be ignored when sending a request. :ivar value: Performance level value. :vartype value: float - :ivar unit: Unit type used to measure performance level. Known values are: "DTU", "VCores". + :ivar unit: Unit type used to measure performance level. Known values are: "DTU" and "VCores". :vartype unit: str or ~azure.mgmt.sql.models.PerformanceLevelUnit """ _validation = { - 'value': {'readonly': True}, - 'unit': {'readonly': True}, + "value": {"readonly": True}, + "unit": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': 'float'}, - 'unit': {'key': 'unit', 'type': 'str'}, + "value": {"key": "value", "type": "float"}, + "unit": {"key": "unit", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(PerformanceLevelCapability, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.unit = None @@ -13351,24 +13301,27 @@ class PrivateEndpointConnection(ProxyResource): :vartype private_link_service_connection_state: ~azure.mgmt.sql.models.PrivateLinkServiceConnectionStateProperty :ivar provisioning_state: State of the private endpoint connection. Known values are: - "Approving", "Ready", "Dropping", "Failed", "Rejecting". + "Approving", "Ready", "Dropping", "Failed", and "Rejecting". :vartype provisioning_state: str or ~azure.mgmt.sql.models.PrivateEndpointProvisioningState """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'provisioning_state': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "provisioning_state": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'private_endpoint': {'key': 'properties.privateEndpoint', 'type': 'PrivateEndpointProperty'}, - 'private_link_service_connection_state': {'key': 'properties.privateLinkServiceConnectionState', 'type': 'PrivateLinkServiceConnectionStateProperty'}, - 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "private_endpoint": {"key": "properties.privateEndpoint", "type": "PrivateEndpointProperty"}, + "private_link_service_connection_state": { + "key": "properties.privateLinkServiceConnectionState", + "type": "PrivateLinkServiceConnectionStateProperty", + }, + "provisioning_state": {"key": "properties.provisioningState", "type": "str"}, } def __init__( @@ -13386,13 +13339,13 @@ def __init__( :paramtype private_link_service_connection_state: ~azure.mgmt.sql.models.PrivateLinkServiceConnectionStateProperty """ - super(PrivateEndpointConnection, self).__init__(**kwargs) + super().__init__(**kwargs) self.private_endpoint = private_endpoint self.private_link_service_connection_state = private_link_service_connection_state self.provisioning_state = None -class PrivateEndpointConnectionListResult(msrest.serialization.Model): +class PrivateEndpointConnectionListResult(_serialization.Model): """A list of private endpoint connections. Variables are only populated by the server, and will be ignored when sending a request. @@ -13404,27 +13357,23 @@ class PrivateEndpointConnectionListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[PrivateEndpointConnection]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[PrivateEndpointConnection]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(PrivateEndpointConnectionListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class PrivateEndpointConnectionProperties(msrest.serialization.Model): +class PrivateEndpointConnectionProperties(_serialization.Model): """Properties of a private endpoint connection. Variables are only populated by the server, and will be ignored when sending a request. @@ -13436,18 +13385,21 @@ class PrivateEndpointConnectionProperties(msrest.serialization.Model): :vartype private_link_service_connection_state: ~azure.mgmt.sql.models.PrivateLinkServiceConnectionStateProperty :ivar provisioning_state: State of the private endpoint connection. Known values are: - "Approving", "Ready", "Dropping", "Failed", "Rejecting". + "Approving", "Ready", "Dropping", "Failed", and "Rejecting". :vartype provisioning_state: str or ~azure.mgmt.sql.models.PrivateEndpointProvisioningState """ _validation = { - 'provisioning_state': {'readonly': True}, + "provisioning_state": {"readonly": True}, } _attribute_map = { - 'private_endpoint': {'key': 'privateEndpoint', 'type': 'PrivateEndpointProperty'}, - 'private_link_service_connection_state': {'key': 'privateLinkServiceConnectionState', 'type': 'PrivateLinkServiceConnectionStateProperty'}, - 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + "private_endpoint": {"key": "privateEndpoint", "type": "PrivateEndpointProperty"}, + "private_link_service_connection_state": { + "key": "privateLinkServiceConnectionState", + "type": "PrivateLinkServiceConnectionStateProperty", + }, + "provisioning_state": {"key": "provisioningState", "type": "str"}, } def __init__( @@ -13465,13 +13417,13 @@ def __init__( :paramtype private_link_service_connection_state: ~azure.mgmt.sql.models.PrivateLinkServiceConnectionStateProperty """ - super(PrivateEndpointConnectionProperties, self).__init__(**kwargs) + super().__init__(**kwargs) self.private_endpoint = private_endpoint self.private_link_service_connection_state = private_link_service_connection_state self.provisioning_state = None -class PrivateEndpointConnectionRequestStatus(msrest.serialization.Model): +class PrivateEndpointConnectionRequestStatus(_serialization.Model): """Contains the private endpoint connection requests status. Variables are only populated by the server, and will be ignored when sending a request. @@ -13485,30 +13437,26 @@ class PrivateEndpointConnectionRequestStatus(msrest.serialization.Model): """ _validation = { - 'private_link_service_id': {'readonly': True}, - 'private_endpoint_connection_name': {'readonly': True}, - 'status': {'readonly': True}, + "private_link_service_id": {"readonly": True}, + "private_endpoint_connection_name": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'private_link_service_id': {'key': 'privateLinkServiceId', 'type': 'str'}, - 'private_endpoint_connection_name': {'key': 'privateEndpointConnectionName', 'type': 'str'}, - 'status': {'key': 'status', 'type': 'str'}, + "private_link_service_id": {"key": "privateLinkServiceId", "type": "str"}, + "private_endpoint_connection_name": {"key": "privateEndpointConnectionName", "type": "str"}, + "status": {"key": "status", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(PrivateEndpointConnectionRequestStatus, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.private_link_service_id = None self.private_endpoint_connection_name = None self.status = None -class PrivateEndpointProperty(msrest.serialization.Model): +class PrivateEndpointProperty(_serialization.Model): """PrivateEndpointProperty. :ivar id: Resource id of the private endpoint. @@ -13516,20 +13464,15 @@ class PrivateEndpointProperty(msrest.serialization.Model): """ _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, } - def __init__( - self, - *, - id: Optional[str] = None, - **kwargs - ): + def __init__(self, *, id: Optional[str] = None, **kwargs): # pylint: disable=redefined-builtin """ :keyword id: Resource id of the private endpoint. :paramtype id: str """ - super(PrivateEndpointProperty, self).__init__(**kwargs) + super().__init__(**kwargs) self.id = id @@ -13549,30 +13492,26 @@ class PrivateLinkResource(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'properties': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "properties": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'properties': {'key': 'properties', 'type': 'PrivateLinkResourceProperties'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "properties": {"key": "properties", "type": "PrivateLinkResourceProperties"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(PrivateLinkResource, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.properties = None -class PrivateLinkResourceListResult(msrest.serialization.Model): +class PrivateLinkResourceListResult(_serialization.Model): """A list of private link resources. Variables are only populated by the server, and will be ignored when sending a request. @@ -13584,27 +13523,23 @@ class PrivateLinkResourceListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[PrivateLinkResource]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[PrivateLinkResource]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(PrivateLinkResourceListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class PrivateLinkResourceProperties(msrest.serialization.Model): +class PrivateLinkResourceProperties(_serialization.Model): """Properties of a private link resource. Variables are only populated by the server, and will be ignored when sending a request. @@ -13618,125 +13553,111 @@ class PrivateLinkResourceProperties(msrest.serialization.Model): """ _validation = { - 'group_id': {'readonly': True}, - 'required_members': {'readonly': True}, - 'required_zone_names': {'readonly': True}, + "group_id": {"readonly": True}, + "required_members": {"readonly": True}, + "required_zone_names": {"readonly": True}, } _attribute_map = { - 'group_id': {'key': 'groupId', 'type': 'str'}, - 'required_members': {'key': 'requiredMembers', 'type': '[str]'}, - 'required_zone_names': {'key': 'requiredZoneNames', 'type': '[str]'}, + "group_id": {"key": "groupId", "type": "str"}, + "required_members": {"key": "requiredMembers", "type": "[str]"}, + "required_zone_names": {"key": "requiredZoneNames", "type": "[str]"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(PrivateLinkResourceProperties, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.group_id = None self.required_members = None self.required_zone_names = None -class PrivateLinkServiceConnectionStateProperty(msrest.serialization.Model): +class PrivateLinkServiceConnectionStateProperty(_serialization.Model): """PrivateLinkServiceConnectionStateProperty. Variables are only populated by the server, and will be ignored when sending a request. All required parameters must be populated in order to send to Azure. - :ivar status: Required. The private link service connection status. Known values are: - "Approved", "Pending", "Rejected", "Disconnected". + :ivar status: The private link service connection status. Required. Known values are: + "Approved", "Pending", "Rejected", and "Disconnected". :vartype status: str or ~azure.mgmt.sql.models.PrivateLinkServiceConnectionStateStatus - :ivar description: Required. The private link service connection description. + :ivar description: The private link service connection description. Required. :vartype description: str - :ivar actions_required: The actions required for private link service connection. Known values - are: "None". + :ivar actions_required: The actions required for private link service connection. "None" :vartype actions_required: str or ~azure.mgmt.sql.models.PrivateLinkServiceConnectionStateActionsRequire """ _validation = { - 'status': {'required': True}, - 'description': {'required': True}, - 'actions_required': {'readonly': True}, + "status": {"required": True}, + "description": {"required": True}, + "actions_required": {"readonly": True}, } _attribute_map = { - 'status': {'key': 'status', 'type': 'str'}, - 'description': {'key': 'description', 'type': 'str'}, - 'actions_required': {'key': 'actionsRequired', 'type': 'str'}, + "status": {"key": "status", "type": "str"}, + "description": {"key": "description", "type": "str"}, + "actions_required": {"key": "actionsRequired", "type": "str"}, } def __init__( - self, - *, - status: Union[str, "_models.PrivateLinkServiceConnectionStateStatus"], - description: str, - **kwargs + self, *, status: Union[str, "_models.PrivateLinkServiceConnectionStateStatus"], description: str, **kwargs ): """ - :keyword status: Required. The private link service connection status. Known values are: - "Approved", "Pending", "Rejected", "Disconnected". + :keyword status: The private link service connection status. Required. Known values are: + "Approved", "Pending", "Rejected", and "Disconnected". :paramtype status: str or ~azure.mgmt.sql.models.PrivateLinkServiceConnectionStateStatus - :keyword description: Required. The private link service connection description. + :keyword description: The private link service connection description. Required. :paramtype description: str """ - super(PrivateLinkServiceConnectionStateProperty, self).__init__(**kwargs) + super().__init__(**kwargs) self.status = status self.description = description self.actions_required = None -class QueryMetricInterval(msrest.serialization.Model): +class QueryMetricInterval(_serialization.Model): """Properties of a query metrics interval. Variables are only populated by the server, and will be ignored when sending a request. :ivar interval_start_time: The start time for the metric interval (ISO-8601 format). :vartype interval_start_time: str - :ivar interval_type: Interval type (length). Known values are: "PT1H", "P1D". + :ivar interval_type: Interval type (length). Known values are: "PT1H" and "P1D". :vartype interval_type: str or ~azure.mgmt.sql.models.QueryTimeGrainType :ivar execution_count: Execution count of a query in this interval. - :vartype execution_count: long + :vartype execution_count: int :ivar metrics: List of metric objects for this interval. :vartype metrics: list[~azure.mgmt.sql.models.QueryMetricProperties] """ _validation = { - 'interval_start_time': {'readonly': True}, - 'interval_type': {'readonly': True}, - 'execution_count': {'readonly': True}, + "interval_start_time": {"readonly": True}, + "interval_type": {"readonly": True}, + "execution_count": {"readonly": True}, } _attribute_map = { - 'interval_start_time': {'key': 'intervalStartTime', 'type': 'str'}, - 'interval_type': {'key': 'intervalType', 'type': 'str'}, - 'execution_count': {'key': 'executionCount', 'type': 'long'}, - 'metrics': {'key': 'metrics', 'type': '[QueryMetricProperties]'}, + "interval_start_time": {"key": "intervalStartTime", "type": "str"}, + "interval_type": {"key": "intervalType", "type": "str"}, + "execution_count": {"key": "executionCount", "type": "int"}, + "metrics": {"key": "metrics", "type": "[QueryMetricProperties]"}, } - def __init__( - self, - *, - metrics: Optional[List["_models.QueryMetricProperties"]] = None, - **kwargs - ): + def __init__(self, *, metrics: Optional[List["_models.QueryMetricProperties"]] = None, **kwargs): """ :keyword metrics: List of metric objects for this interval. :paramtype metrics: list[~azure.mgmt.sql.models.QueryMetricProperties] """ - super(QueryMetricInterval, self).__init__(**kwargs) + super().__init__(**kwargs) self.interval_start_time = None self.interval_type = None self.execution_count = None self.metrics = metrics -class QueryMetricProperties(msrest.serialization.Model): +class QueryMetricProperties(_serialization.Model): """Properties of a topquery metric in one interval. Variables are only populated by the server, and will be ignored when sending a request. @@ -13745,7 +13666,7 @@ class QueryMetricProperties(msrest.serialization.Model): :vartype name: str :ivar display_name: The UI appropriate name for the metric. :vartype display_name: str - :ivar unit: The unit of the metric. Known values are: "percentage", "KB", "microseconds", + :ivar unit: The unit of the metric. Known values are: "percentage", "KB", "microseconds", and "count". :vartype unit: str or ~azure.mgmt.sql.models.QueryMetricUnitType :ivar value: The value of the metric. @@ -13763,36 +13684,32 @@ class QueryMetricProperties(msrest.serialization.Model): """ _validation = { - 'name': {'readonly': True}, - 'display_name': {'readonly': True}, - 'unit': {'readonly': True}, - 'value': {'readonly': True}, - 'min': {'readonly': True}, - 'max': {'readonly': True}, - 'avg': {'readonly': True}, - 'sum': {'readonly': True}, - 'stdev': {'readonly': True}, + "name": {"readonly": True}, + "display_name": {"readonly": True}, + "unit": {"readonly": True}, + "value": {"readonly": True}, + "min": {"readonly": True}, + "max": {"readonly": True}, + "avg": {"readonly": True}, + "sum": {"readonly": True}, + "stdev": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'display_name': {'key': 'displayName', 'type': 'str'}, - 'unit': {'key': 'unit', 'type': 'str'}, - 'value': {'key': 'value', 'type': 'float'}, - 'min': {'key': 'min', 'type': 'float'}, - 'max': {'key': 'max', 'type': 'float'}, - 'avg': {'key': 'avg', 'type': 'float'}, - 'sum': {'key': 'sum', 'type': 'float'}, - 'stdev': {'key': 'stdev', 'type': 'float'}, + "name": {"key": "name", "type": "str"}, + "display_name": {"key": "displayName", "type": "str"}, + "unit": {"key": "unit", "type": "str"}, + "value": {"key": "value", "type": "float"}, + "min": {"key": "min", "type": "float"}, + "max": {"key": "max", "type": "float"}, + "avg": {"key": "avg", "type": "float"}, + "sum": {"key": "sum", "type": "float"}, + "stdev": {"key": "stdev", "type": "float"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(QueryMetricProperties, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.name = None self.display_name = None self.unit = None @@ -13828,37 +13745,32 @@ class QueryStatistics(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'database_name': {'readonly': True}, - 'query_id': {'readonly': True}, - 'start_time': {'readonly': True}, - 'end_time': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "database_name": {"readonly": True}, + "query_id": {"readonly": True}, + "start_time": {"readonly": True}, + "end_time": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'database_name': {'key': 'properties.databaseName', 'type': 'str'}, - 'query_id': {'key': 'properties.queryId', 'type': 'str'}, - 'start_time': {'key': 'properties.startTime', 'type': 'str'}, - 'end_time': {'key': 'properties.endTime', 'type': 'str'}, - 'intervals': {'key': 'properties.intervals', 'type': '[QueryMetricInterval]'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "database_name": {"key": "properties.databaseName", "type": "str"}, + "query_id": {"key": "properties.queryId", "type": "str"}, + "start_time": {"key": "properties.startTime", "type": "str"}, + "end_time": {"key": "properties.endTime", "type": "str"}, + "intervals": {"key": "properties.intervals", "type": "[QueryMetricInterval]"}, } - def __init__( - self, - *, - intervals: Optional[List["_models.QueryMetricInterval"]] = None, - **kwargs - ): + def __init__(self, *, intervals: Optional[List["_models.QueryMetricInterval"]] = None, **kwargs): """ :keyword intervals: List of intervals with appropriate metric data. :paramtype intervals: list[~azure.mgmt.sql.models.QueryMetricInterval] """ - super(QueryStatistics, self).__init__(**kwargs) + super().__init__(**kwargs) self.database_name = None self.query_id = None self.start_time = None @@ -13866,7 +13778,7 @@ def __init__( self.intervals = intervals -class QueryStatisticsProperties(msrest.serialization.Model): +class QueryStatisticsProperties(_serialization.Model): """Properties of a query execution statistics. Variables are only populated by the server, and will be ignored when sending a request. @@ -13884,31 +13796,26 @@ class QueryStatisticsProperties(msrest.serialization.Model): """ _validation = { - 'database_name': {'readonly': True}, - 'query_id': {'readonly': True}, - 'start_time': {'readonly': True}, - 'end_time': {'readonly': True}, + "database_name": {"readonly": True}, + "query_id": {"readonly": True}, + "start_time": {"readonly": True}, + "end_time": {"readonly": True}, } _attribute_map = { - 'database_name': {'key': 'databaseName', 'type': 'str'}, - 'query_id': {'key': 'queryId', 'type': 'str'}, - 'start_time': {'key': 'startTime', 'type': 'str'}, - 'end_time': {'key': 'endTime', 'type': 'str'}, - 'intervals': {'key': 'intervals', 'type': '[QueryMetricInterval]'}, + "database_name": {"key": "databaseName", "type": "str"}, + "query_id": {"key": "queryId", "type": "str"}, + "start_time": {"key": "startTime", "type": "str"}, + "end_time": {"key": "endTime", "type": "str"}, + "intervals": {"key": "intervals", "type": "[QueryMetricInterval]"}, } - def __init__( - self, - *, - intervals: Optional[List["_models.QueryMetricInterval"]] = None, - **kwargs - ): + def __init__(self, *, intervals: Optional[List["_models.QueryMetricInterval"]] = None, **kwargs): """ :keyword intervals: List of intervals with appropriate metric data. :paramtype intervals: list[~azure.mgmt.sql.models.QueryMetricInterval] """ - super(QueryStatisticsProperties, self).__init__(**kwargs) + super().__init__(**kwargs) self.database_name = None self.query_id = None self.start_time = None @@ -13916,7 +13823,7 @@ def __init__( self.intervals = intervals -class ReadScaleCapability(msrest.serialization.Model): +class ReadScaleCapability(_serialization.Model): """The read scale capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -13924,40 +13831,35 @@ class ReadScaleCapability(msrest.serialization.Model): :ivar max_number_of_replicas: The maximum number of read scale replicas. :vartype max_number_of_replicas: int :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'max_number_of_replicas': {'readonly': True}, - 'status': {'readonly': True}, + "max_number_of_replicas": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'max_number_of_replicas': {'key': 'maxNumberOfReplicas', 'type': 'int'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "max_number_of_replicas": {"key": "maxNumberOfReplicas", "type": "int"}, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(ReadScaleCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.max_number_of_replicas = None self.status = None self.reason = reason -class RecommendedAction(ProxyResource): +class RecommendedAction(ProxyResource): # pylint: disable=too-many-instance-attributes """Database, Server or Elastic Pool Recommended Action. Variables are only populated by the server, and will be ignored when sending a request. @@ -14002,14 +13904,14 @@ class RecommendedAction(ProxyResource): action on user resource. e.g., time taken for dropping the created index. :vartype revert_action_duration: str :ivar execute_action_initiated_by: Gets if approval for applying this recommended action was - given by user/system. Known values are: "User", "System". + given by user/system. Known values are: "User" and "System". :vartype execute_action_initiated_by: str or ~azure.mgmt.sql.models.RecommendedActionInitiatedBy :ivar execute_action_initiated_time: Gets the time when this recommended action was approved for execution. :vartype execute_action_initiated_time: ~datetime.datetime :ivar revert_action_initiated_by: Gets if approval for reverting this recommended action was - given by user/system. Known values are: "User", "System". + given by user/system. Known values are: "User" and "System". :vartype revert_action_initiated_by: str or ~azure.mgmt.sql.models.RecommendedActionInitiatedBy :ivar revert_action_initiated_time: Gets the time when this recommended action was approved for revert. @@ -14035,81 +13937,81 @@ class RecommendedAction(ProxyResource): :ivar linked_objects: Gets the linked objects, if any. :vartype linked_objects: list[str] :ivar details: Gets additional details specific to this recommended action. - :vartype details: dict[str, any] - """ - - _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'kind': {'readonly': True}, - 'location': {'readonly': True}, - 'recommendation_reason': {'readonly': True}, - 'valid_since': {'readonly': True}, - 'last_refresh': {'readonly': True}, - 'is_executable_action': {'readonly': True}, - 'is_revertable_action': {'readonly': True}, - 'is_archived_action': {'readonly': True}, - 'execute_action_start_time': {'readonly': True}, - 'execute_action_duration': {'readonly': True}, - 'revert_action_start_time': {'readonly': True}, - 'revert_action_duration': {'readonly': True}, - 'execute_action_initiated_by': {'readonly': True}, - 'execute_action_initiated_time': {'readonly': True}, - 'revert_action_initiated_by': {'readonly': True}, - 'revert_action_initiated_time': {'readonly': True}, - 'score': {'readonly': True}, - 'implementation_details': {'readonly': True}, - 'error_details': {'readonly': True}, - 'estimated_impact': {'readonly': True}, - 'observed_impact': {'readonly': True}, - 'time_series': {'readonly': True}, - 'linked_objects': {'readonly': True}, - 'details': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'kind': {'key': 'kind', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'recommendation_reason': {'key': 'properties.recommendationReason', 'type': 'str'}, - 'valid_since': {'key': 'properties.validSince', 'type': 'iso-8601'}, - 'last_refresh': {'key': 'properties.lastRefresh', 'type': 'iso-8601'}, - 'state': {'key': 'properties.state', 'type': 'RecommendedActionStateInfo'}, - 'is_executable_action': {'key': 'properties.isExecutableAction', 'type': 'bool'}, - 'is_revertable_action': {'key': 'properties.isRevertableAction', 'type': 'bool'}, - 'is_archived_action': {'key': 'properties.isArchivedAction', 'type': 'bool'}, - 'execute_action_start_time': {'key': 'properties.executeActionStartTime', 'type': 'iso-8601'}, - 'execute_action_duration': {'key': 'properties.executeActionDuration', 'type': 'str'}, - 'revert_action_start_time': {'key': 'properties.revertActionStartTime', 'type': 'iso-8601'}, - 'revert_action_duration': {'key': 'properties.revertActionDuration', 'type': 'str'}, - 'execute_action_initiated_by': {'key': 'properties.executeActionInitiatedBy', 'type': 'str'}, - 'execute_action_initiated_time': {'key': 'properties.executeActionInitiatedTime', 'type': 'iso-8601'}, - 'revert_action_initiated_by': {'key': 'properties.revertActionInitiatedBy', 'type': 'str'}, - 'revert_action_initiated_time': {'key': 'properties.revertActionInitiatedTime', 'type': 'iso-8601'}, - 'score': {'key': 'properties.score', 'type': 'int'}, - 'implementation_details': {'key': 'properties.implementationDetails', 'type': 'RecommendedActionImplementationInfo'}, - 'error_details': {'key': 'properties.errorDetails', 'type': 'RecommendedActionErrorInfo'}, - 'estimated_impact': {'key': 'properties.estimatedImpact', 'type': '[RecommendedActionImpactRecord]'}, - 'observed_impact': {'key': 'properties.observedImpact', 'type': '[RecommendedActionImpactRecord]'}, - 'time_series': {'key': 'properties.timeSeries', 'type': '[RecommendedActionMetricInfo]'}, - 'linked_objects': {'key': 'properties.linkedObjects', 'type': '[str]'}, - 'details': {'key': 'properties.details', 'type': '{object}'}, - } - - def __init__( - self, - *, - state: Optional["_models.RecommendedActionStateInfo"] = None, - **kwargs + :vartype details: dict[str, JSON] + """ + + _validation = { + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "kind": {"readonly": True}, + "location": {"readonly": True}, + "recommendation_reason": {"readonly": True}, + "valid_since": {"readonly": True}, + "last_refresh": {"readonly": True}, + "is_executable_action": {"readonly": True}, + "is_revertable_action": {"readonly": True}, + "is_archived_action": {"readonly": True}, + "execute_action_start_time": {"readonly": True}, + "execute_action_duration": {"readonly": True}, + "revert_action_start_time": {"readonly": True}, + "revert_action_duration": {"readonly": True}, + "execute_action_initiated_by": {"readonly": True}, + "execute_action_initiated_time": {"readonly": True}, + "revert_action_initiated_by": {"readonly": True}, + "revert_action_initiated_time": {"readonly": True}, + "score": {"readonly": True}, + "implementation_details": {"readonly": True}, + "error_details": {"readonly": True}, + "estimated_impact": {"readonly": True}, + "observed_impact": {"readonly": True}, + "time_series": {"readonly": True}, + "linked_objects": {"readonly": True}, + "details": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "kind": {"key": "kind", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "recommendation_reason": {"key": "properties.recommendationReason", "type": "str"}, + "valid_since": {"key": "properties.validSince", "type": "iso-8601"}, + "last_refresh": {"key": "properties.lastRefresh", "type": "iso-8601"}, + "state": {"key": "properties.state", "type": "RecommendedActionStateInfo"}, + "is_executable_action": {"key": "properties.isExecutableAction", "type": "bool"}, + "is_revertable_action": {"key": "properties.isRevertableAction", "type": "bool"}, + "is_archived_action": {"key": "properties.isArchivedAction", "type": "bool"}, + "execute_action_start_time": {"key": "properties.executeActionStartTime", "type": "iso-8601"}, + "execute_action_duration": {"key": "properties.executeActionDuration", "type": "str"}, + "revert_action_start_time": {"key": "properties.revertActionStartTime", "type": "iso-8601"}, + "revert_action_duration": {"key": "properties.revertActionDuration", "type": "str"}, + "execute_action_initiated_by": {"key": "properties.executeActionInitiatedBy", "type": "str"}, + "execute_action_initiated_time": {"key": "properties.executeActionInitiatedTime", "type": "iso-8601"}, + "revert_action_initiated_by": {"key": "properties.revertActionInitiatedBy", "type": "str"}, + "revert_action_initiated_time": {"key": "properties.revertActionInitiatedTime", "type": "iso-8601"}, + "score": {"key": "properties.score", "type": "int"}, + "implementation_details": { + "key": "properties.implementationDetails", + "type": "RecommendedActionImplementationInfo", + }, + "error_details": {"key": "properties.errorDetails", "type": "RecommendedActionErrorInfo"}, + "estimated_impact": {"key": "properties.estimatedImpact", "type": "[RecommendedActionImpactRecord]"}, + "observed_impact": {"key": "properties.observedImpact", "type": "[RecommendedActionImpactRecord]"}, + "time_series": {"key": "properties.timeSeries", "type": "[RecommendedActionMetricInfo]"}, + "linked_objects": {"key": "properties.linkedObjects", "type": "[str]"}, + "details": {"key": "properties.details", "type": "{object}"}, + } + + def __init__( # pylint: disable=too-many-locals + self, *, state: Optional["_models.RecommendedActionStateInfo"] = None, **kwargs ): """ :keyword state: Gets the info of the current state the recommended action is in. :paramtype state: ~azure.mgmt.sql.models.RecommendedActionStateInfo """ - super(RecommendedAction, self).__init__(**kwargs) + super().__init__(**kwargs) self.kind = None self.location = None self.recommendation_reason = None @@ -14137,7 +14039,7 @@ def __init__( self.details = None -class RecommendedActionErrorInfo(msrest.serialization.Model): +class RecommendedActionErrorInfo(_serialization.Model): """Contains error information for an Azure SQL Database, Server or Elastic Pool Recommended Action. Variables are only populated by the server, and will be ignored when sending a request. @@ -14146,32 +14048,28 @@ class RecommendedActionErrorInfo(msrest.serialization.Model): DatabaseHasQdsOff, IndexAlreadyExists. :vartype error_code: str :ivar is_retryable: Gets whether the error could be ignored and recommended action could be - retried. Possible values are: Yes/No. Known values are: "Yes", "No". + retried. Possible values are: Yes/No. Known values are: "Yes" and "No". :vartype is_retryable: str or ~azure.mgmt.sql.models.IsRetryable """ _validation = { - 'error_code': {'readonly': True}, - 'is_retryable': {'readonly': True}, + "error_code": {"readonly": True}, + "is_retryable": {"readonly": True}, } _attribute_map = { - 'error_code': {'key': 'errorCode', 'type': 'str'}, - 'is_retryable': {'key': 'isRetryable', 'type': 'str'}, + "error_code": {"key": "errorCode", "type": "str"}, + "is_retryable": {"key": "isRetryable", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(RecommendedActionErrorInfo, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.error_code = None self.is_retryable = None -class RecommendedActionImpactRecord(msrest.serialization.Model): +class RecommendedActionImpactRecord(_serialization.Model): """Contains information of estimated or observed impact on various metrics for an Azure SQL Database, Server or Elastic Pool Recommended Action. Variables are only populated by the server, and will be ignored when sending a request. @@ -14194,28 +14092,24 @@ class RecommendedActionImpactRecord(msrest.serialization.Model): """ _validation = { - 'dimension_name': {'readonly': True}, - 'unit': {'readonly': True}, - 'absolute_value': {'readonly': True}, - 'change_value_absolute': {'readonly': True}, - 'change_value_relative': {'readonly': True}, + "dimension_name": {"readonly": True}, + "unit": {"readonly": True}, + "absolute_value": {"readonly": True}, + "change_value_absolute": {"readonly": True}, + "change_value_relative": {"readonly": True}, } _attribute_map = { - 'dimension_name': {'key': 'dimensionName', 'type': 'str'}, - 'unit': {'key': 'unit', 'type': 'str'}, - 'absolute_value': {'key': 'absoluteValue', 'type': 'float'}, - 'change_value_absolute': {'key': 'changeValueAbsolute', 'type': 'float'}, - 'change_value_relative': {'key': 'changeValueRelative', 'type': 'float'}, + "dimension_name": {"key": "dimensionName", "type": "str"}, + "unit": {"key": "unit", "type": "str"}, + "absolute_value": {"key": "absoluteValue", "type": "float"}, + "change_value_absolute": {"key": "changeValueAbsolute", "type": "float"}, + "change_value_relative": {"key": "changeValueRelative", "type": "float"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(RecommendedActionImpactRecord, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.dimension_name = None self.unit = None self.absolute_value = None @@ -14223,13 +14117,13 @@ def __init__( self.change_value_relative = None -class RecommendedActionImplementationInfo(msrest.serialization.Model): +class RecommendedActionImplementationInfo(_serialization.Model): """Contains information for manual implementation for an Azure SQL Database, Server or Elastic Pool Recommended Action. Variables are only populated by the server, and will be ignored when sending a request. :ivar method: Gets the method in which this recommended action can be manually implemented. - e.g., TSql, AzurePowerShell. Known values are: "TSql", "AzurePowerShell". + e.g., TSql, AzurePowerShell. Known values are: "TSql" and "AzurePowerShell". :vartype method: str or ~azure.mgmt.sql.models.ImplementationMethod :ivar script: Gets the manual implementation script. e.g., T-SQL script that could be executed on the database. @@ -14237,27 +14131,23 @@ class RecommendedActionImplementationInfo(msrest.serialization.Model): """ _validation = { - 'method': {'readonly': True}, - 'script': {'readonly': True}, + "method": {"readonly": True}, + "script": {"readonly": True}, } _attribute_map = { - 'method': {'key': 'method', 'type': 'str'}, - 'script': {'key': 'script', 'type': 'str'}, + "method": {"key": "method", "type": "str"}, + "script": {"key": "script", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(RecommendedActionImplementationInfo, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.method = None self.script = None -class RecommendedActionMetricInfo(msrest.serialization.Model): +class RecommendedActionMetricInfo(_serialization.Model): """Contains time series of various impacted metrics for an Azure SQL Database, Server or Elastic Pool Recommended Action. Variables are only populated by the server, and will be ignored when sending a request. @@ -14276,28 +14166,24 @@ class RecommendedActionMetricInfo(msrest.serialization.Model): """ _validation = { - 'metric_name': {'readonly': True}, - 'unit': {'readonly': True}, - 'time_grain': {'readonly': True}, - 'start_time': {'readonly': True}, - 'value': {'readonly': True}, + "metric_name": {"readonly": True}, + "unit": {"readonly": True}, + "time_grain": {"readonly": True}, + "start_time": {"readonly": True}, + "value": {"readonly": True}, } _attribute_map = { - 'metric_name': {'key': 'metricName', 'type': 'str'}, - 'unit': {'key': 'unit', 'type': 'str'}, - 'time_grain': {'key': 'timeGrain', 'type': 'str'}, - 'start_time': {'key': 'startTime', 'type': 'iso-8601'}, - 'value': {'key': 'value', 'type': 'float'}, + "metric_name": {"key": "metricName", "type": "str"}, + "unit": {"key": "unit", "type": "str"}, + "time_grain": {"key": "timeGrain", "type": "str"}, + "start_time": {"key": "startTime", "type": "iso-8601"}, + "value": {"key": "value", "type": "float"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(RecommendedActionMetricInfo, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.metric_name = None self.unit = None self.time_grain = None @@ -14305,71 +14191,66 @@ def __init__( self.value = None -class RecommendedActionStateInfo(msrest.serialization.Model): +class RecommendedActionStateInfo(_serialization.Model): """Contains information of current state for an Azure SQL Database, Server or Elastic Pool Recommended Action. Variables are only populated by the server, and will be ignored when sending a request. All required parameters must be populated in order to send to Azure. - :ivar current_value: Required. Current state the recommended action is in. Some commonly used - states are: Active -> recommended action is active and no action has been taken yet. - Pending -> recommended action is approved for and is awaiting execution. Executing -> - recommended action is being applied on the user database. Verifying -> recommended action was - applied and is being verified of its usefulness by the system. Success -> recommended - action was applied and improvement found during verification. Pending Revert -> verification - found little or no improvement so recommended action is queued for revert or user has manually - reverted. Reverting -> changes made while applying recommended action are being reverted on - the user database. Reverted -> successfully reverted the changes made by recommended action - on user database. Ignored -> user explicitly ignored/discarded the recommended action. - Known values are: "Active", "Pending", "Executing", "Verifying", "PendingRevert", - "RevertCancelled", "Reverting", "Reverted", "Ignored", "Expired", "Monitoring", "Resolved", - "Success", "Error". + :ivar current_value: Current state the recommended action is in. Some commonly used states are: + Active -> recommended action is active and no action has been taken yet. Pending -> + recommended action is approved for and is awaiting execution. Executing -> recommended action + is being applied on the user database. Verifying -> recommended action was applied and is + being verified of its usefulness by the system. Success -> recommended action was applied + and improvement found during verification. Pending Revert -> verification found little or no + improvement so recommended action is queued for revert or user has manually reverted. Reverting + -> changes made while applying recommended action are being reverted on the user database. + Reverted -> successfully reverted the changes made by recommended action on user database. + Ignored -> user explicitly ignored/discarded the recommended action. Required. Known values + are: "Active", "Pending", "Executing", "Verifying", "PendingRevert", "RevertCancelled", + "Reverting", "Reverted", "Ignored", "Expired", "Monitoring", "Resolved", "Success", and + "Error". :vartype current_value: str or ~azure.mgmt.sql.models.RecommendedActionCurrentState :ivar action_initiated_by: Gets who initiated the execution of this recommended action. Possible Value are: User -> When user explicity notified system to apply the recommended action. System -> When auto-execute status of this advisor was set to 'Enabled', in which case - the system applied it. Known values are: "User", "System". + the system applied it. Known values are: "User" and "System". :vartype action_initiated_by: str or ~azure.mgmt.sql.models.RecommendedActionInitiatedBy :ivar last_modified: Gets the time when the state was last modified. :vartype last_modified: ~datetime.datetime """ _validation = { - 'current_value': {'required': True}, - 'action_initiated_by': {'readonly': True}, - 'last_modified': {'readonly': True}, + "current_value": {"required": True}, + "action_initiated_by": {"readonly": True}, + "last_modified": {"readonly": True}, } _attribute_map = { - 'current_value': {'key': 'currentValue', 'type': 'str'}, - 'action_initiated_by': {'key': 'actionInitiatedBy', 'type': 'str'}, - 'last_modified': {'key': 'lastModified', 'type': 'iso-8601'}, + "current_value": {"key": "currentValue", "type": "str"}, + "action_initiated_by": {"key": "actionInitiatedBy", "type": "str"}, + "last_modified": {"key": "lastModified", "type": "iso-8601"}, } - def __init__( - self, - *, - current_value: Union[str, "_models.RecommendedActionCurrentState"], - **kwargs - ): + def __init__(self, *, current_value: Union[str, "_models.RecommendedActionCurrentState"], **kwargs): """ - :keyword current_value: Required. Current state the recommended action is in. Some commonly - used states are: Active -> recommended action is active and no action has been taken yet. - Pending -> recommended action is approved for and is awaiting execution. Executing -> - recommended action is being applied on the user database. Verifying -> recommended action was - applied and is being verified of its usefulness by the system. Success -> recommended - action was applied and improvement found during verification. Pending Revert -> verification - found little or no improvement so recommended action is queued for revert or user has manually - reverted. Reverting -> changes made while applying recommended action are being reverted on - the user database. Reverted -> successfully reverted the changes made by recommended action - on user database. Ignored -> user explicitly ignored/discarded the recommended action. + :keyword current_value: Current state the recommended action is in. Some commonly used states + are: Active -> recommended action is active and no action has been taken yet. Pending + -> recommended action is approved for and is awaiting execution. Executing -> recommended + action is being applied on the user database. Verifying -> recommended action was applied and + is being verified of its usefulness by the system. Success -> recommended action was + applied and improvement found during verification. Pending Revert -> verification found little + or no improvement so recommended action is queued for revert or user has manually reverted. + Reverting -> changes made while applying recommended action are being reverted on the user + database. Reverted -> successfully reverted the changes made by recommended action on user + database. Ignored -> user explicitly ignored/discarded the recommended action. Required. Known values are: "Active", "Pending", "Executing", "Verifying", "PendingRevert", "RevertCancelled", "Reverting", "Reverted", "Ignored", "Expired", "Monitoring", "Resolved", - "Success", "Error". + "Success", and "Error". :paramtype current_value: str or ~azure.mgmt.sql.models.RecommendedActionCurrentState """ - super(RecommendedActionStateInfo, self).__init__(**kwargs) + super().__init__(**kwargs) self.current_value = current_value self.action_initiated_by = None self.last_modified = None @@ -14386,7 +14267,7 @@ class RecommendedSensitivityLabelUpdate(ProxyResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar op: Known values are: "enable", "disable". + :ivar op: Known values are: "enable" and "disable". :vartype op: str or ~azure.mgmt.sql.models.RecommendedSensitivityLabelUpdateKind :ivar schema: Schema name of the column to update. :vartype schema: str @@ -14397,19 +14278,19 @@ class RecommendedSensitivityLabelUpdate(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'op': {'key': 'properties.op', 'type': 'str'}, - 'schema': {'key': 'properties.schema', 'type': 'str'}, - 'table': {'key': 'properties.table', 'type': 'str'}, - 'column': {'key': 'properties.column', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "op": {"key": "properties.op", "type": "str"}, + "schema": {"key": "properties.schema", "type": "str"}, + "table": {"key": "properties.table", "type": "str"}, + "column": {"key": "properties.column", "type": "str"}, } def __init__( @@ -14422,7 +14303,7 @@ def __init__( **kwargs ): """ - :keyword op: Known values are: "enable", "disable". + :keyword op: Known values are: "enable" and "disable". :paramtype op: str or ~azure.mgmt.sql.models.RecommendedSensitivityLabelUpdateKind :keyword schema: Schema name of the column to update. :paramtype schema: str @@ -14431,14 +14312,14 @@ def __init__( :keyword column: Column name to update. :paramtype column: str """ - super(RecommendedSensitivityLabelUpdate, self).__init__(**kwargs) + super().__init__(**kwargs) self.op = op self.schema = schema self.table = table self.column = column -class RecommendedSensitivityLabelUpdateList(msrest.serialization.Model): +class RecommendedSensitivityLabelUpdateList(_serialization.Model): """A list of recommended sensitivity label update operations. :ivar operations: @@ -14446,20 +14327,15 @@ class RecommendedSensitivityLabelUpdateList(msrest.serialization.Model): """ _attribute_map = { - 'operations': {'key': 'operations', 'type': '[RecommendedSensitivityLabelUpdate]'}, + "operations": {"key": "operations", "type": "[RecommendedSensitivityLabelUpdate]"}, } - def __init__( - self, - *, - operations: Optional[List["_models.RecommendedSensitivityLabelUpdate"]] = None, - **kwargs - ): + def __init__(self, *, operations: Optional[List["_models.RecommendedSensitivityLabelUpdate"]] = None, **kwargs): """ :keyword operations: :paramtype operations: list[~azure.mgmt.sql.models.RecommendedSensitivityLabelUpdate] """ - super(RecommendedSensitivityLabelUpdateList, self).__init__(**kwargs) + super().__init__(**kwargs) self.operations = operations @@ -14486,66 +14362,57 @@ class RecoverableDatabase(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'edition': {'readonly': True}, - 'service_level_objective': {'readonly': True}, - 'elastic_pool_name': {'readonly': True}, - 'last_available_backup_date': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "edition": {"readonly": True}, + "service_level_objective": {"readonly": True}, + "elastic_pool_name": {"readonly": True}, + "last_available_backup_date": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'edition': {'key': 'properties.edition', 'type': 'str'}, - 'service_level_objective': {'key': 'properties.serviceLevelObjective', 'type': 'str'}, - 'elastic_pool_name': {'key': 'properties.elasticPoolName', 'type': 'str'}, - 'last_available_backup_date': {'key': 'properties.lastAvailableBackupDate', 'type': 'iso-8601'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "edition": {"key": "properties.edition", "type": "str"}, + "service_level_objective": {"key": "properties.serviceLevelObjective", "type": "str"}, + "elastic_pool_name": {"key": "properties.elasticPoolName", "type": "str"}, + "last_available_backup_date": {"key": "properties.lastAvailableBackupDate", "type": "iso-8601"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(RecoverableDatabase, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.edition = None self.service_level_objective = None self.elastic_pool_name = None self.last_available_backup_date = None -class RecoverableDatabaseListResult(msrest.serialization.Model): +class RecoverableDatabaseListResult(_serialization.Model): """The response to a list recoverable databases request. All required parameters must be populated in order to send to Azure. - :ivar value: Required. A list of recoverable databases. + :ivar value: A list of recoverable databases. Required. :vartype value: list[~azure.mgmt.sql.models.RecoverableDatabase] """ _validation = { - 'value': {'required': True}, + "value": {"required": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[RecoverableDatabase]'}, + "value": {"key": "value", "type": "[RecoverableDatabase]"}, } - def __init__( - self, - *, - value: List["_models.RecoverableDatabase"], - **kwargs - ): + def __init__(self, *, value: List["_models.RecoverableDatabase"], **kwargs): """ - :keyword value: Required. A list of recoverable databases. + :keyword value: A list of recoverable databases. Required. :paramtype value: list[~azure.mgmt.sql.models.RecoverableDatabase] """ - super(RecoverableDatabaseListResult, self).__init__(**kwargs) + super().__init__(**kwargs) self.value = value @@ -14565,30 +14432,26 @@ class RecoverableManagedDatabase(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'last_available_backup_date': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "last_available_backup_date": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'last_available_backup_date': {'key': 'properties.lastAvailableBackupDate', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "last_available_backup_date": {"key": "properties.lastAvailableBackupDate", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(RecoverableManagedDatabase, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.last_available_backup_date = None -class RecoverableManagedDatabaseListResult(msrest.serialization.Model): +class RecoverableManagedDatabaseListResult(_serialization.Model): """A list of recoverable managed databases. Variables are only populated by the server, and will be ignored when sending a request. @@ -14600,27 +14463,23 @@ class RecoverableManagedDatabaseListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[RecoverableManagedDatabase]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[RecoverableManagedDatabase]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(RecoverableManagedDatabaseListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ReplicationLink(ProxyResource): +class ReplicationLink(ProxyResource): # pylint: disable=too-many-instance-attributes """A replication link. Variables are only populated by the server, and will be ignored when sending a request. @@ -14638,10 +14497,10 @@ class ReplicationLink(ProxyResource): :ivar partner_location: Resource partner location. :vartype partner_location: str :ivar role: Local replication role. Known values are: "Primary", "Secondary", - "NonReadableSecondary", "Source", "Copy". + "NonReadableSecondary", "Source", and "Copy". :vartype role: str or ~azure.mgmt.sql.models.ReplicationRole :ivar partner_role: Partner replication role. Known values are: "Primary", "Secondary", - "NonReadableSecondary", "Source", "Copy". + "NonReadableSecondary", "Source", and "Copy". :vartype partner_role: str or ~azure.mgmt.sql.models.ReplicationRole :ivar replication_mode: Replication mode. :vartype replication_mode: str @@ -14650,55 +14509,52 @@ class ReplicationLink(ProxyResource): :ivar percent_complete: Seeding completion percentage for the link. :vartype percent_complete: int :ivar replication_state: Replication state (PENDING, SEEDING, CATCHUP, SUSPENDED). Known values - are: "PENDING", "SEEDING", "CATCH_UP", "SUSPENDED". + are: "PENDING", "SEEDING", "CATCH_UP", and "SUSPENDED". :vartype replication_state: str or ~azure.mgmt.sql.models.ReplicationState :ivar is_termination_allowed: Whether the user is currently allowed to terminate the link. :vartype is_termination_allowed: bool - :ivar link_type: Link type (GEO, NAMED). Known values are: "GEO", "NAMED". + :ivar link_type: Link type (GEO, NAMED, STANDBY). Known values are: "GEO", "NAMED", and + "STANDBY". :vartype link_type: str or ~azure.mgmt.sql.models.ReplicationLinkType """ - _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'partner_server': {'readonly': True}, - 'partner_database': {'readonly': True}, - 'partner_location': {'readonly': True}, - 'role': {'readonly': True}, - 'partner_role': {'readonly': True}, - 'replication_mode': {'readonly': True}, - 'start_time': {'readonly': True}, - 'percent_complete': {'readonly': True}, - 'replication_state': {'readonly': True}, - 'is_termination_allowed': {'readonly': True}, - 'link_type': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'partner_server': {'key': 'properties.partnerServer', 'type': 'str'}, - 'partner_database': {'key': 'properties.partnerDatabase', 'type': 'str'}, - 'partner_location': {'key': 'properties.partnerLocation', 'type': 'str'}, - 'role': {'key': 'properties.role', 'type': 'str'}, - 'partner_role': {'key': 'properties.partnerRole', 'type': 'str'}, - 'replication_mode': {'key': 'properties.replicationMode', 'type': 'str'}, - 'start_time': {'key': 'properties.startTime', 'type': 'iso-8601'}, - 'percent_complete': {'key': 'properties.percentComplete', 'type': 'int'}, - 'replication_state': {'key': 'properties.replicationState', 'type': 'str'}, - 'is_termination_allowed': {'key': 'properties.isTerminationAllowed', 'type': 'bool'}, - 'link_type': {'key': 'properties.linkType', 'type': 'str'}, - } - - def __init__( - self, - **kwargs - ): - """ - """ - super(ReplicationLink, self).__init__(**kwargs) + _validation = { + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "partner_server": {"readonly": True}, + "partner_database": {"readonly": True}, + "partner_location": {"readonly": True}, + "role": {"readonly": True}, + "partner_role": {"readonly": True}, + "replication_mode": {"readonly": True}, + "start_time": {"readonly": True}, + "percent_complete": {"readonly": True}, + "replication_state": {"readonly": True}, + "is_termination_allowed": {"readonly": True}, + "link_type": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "partner_server": {"key": "properties.partnerServer", "type": "str"}, + "partner_database": {"key": "properties.partnerDatabase", "type": "str"}, + "partner_location": {"key": "properties.partnerLocation", "type": "str"}, + "role": {"key": "properties.role", "type": "str"}, + "partner_role": {"key": "properties.partnerRole", "type": "str"}, + "replication_mode": {"key": "properties.replicationMode", "type": "str"}, + "start_time": {"key": "properties.startTime", "type": "iso-8601"}, + "percent_complete": {"key": "properties.percentComplete", "type": "int"}, + "replication_state": {"key": "properties.replicationState", "type": "str"}, + "is_termination_allowed": {"key": "properties.isTerminationAllowed", "type": "bool"}, + "link_type": {"key": "properties.linkType", "type": "str"}, + } + + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.partner_server = None self.partner_database = None self.partner_location = None @@ -14712,7 +14568,7 @@ def __init__( self.link_type = None -class ReplicationLinkListResult(msrest.serialization.Model): +class ReplicationLinkListResult(_serialization.Model): """A list of replication links. Variables are only populated by the server, and will be ignored when sending a request. @@ -14724,27 +14580,23 @@ class ReplicationLinkListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ReplicationLink]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ReplicationLink]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ReplicationLinkListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ResourceIdentity(msrest.serialization.Model): +class ResourceIdentity(_serialization.Model): """Azure Active Directory identity configuration for a resource. Variables are only populated by the server, and will be ignored when sending a request. @@ -14755,22 +14607,22 @@ class ResourceIdentity(msrest.serialization.Model): :vartype principal_id: str :ivar type: The identity type. Set this to 'SystemAssigned' in order to automatically create and assign an Azure Active Directory principal for the resource. Known values are: "None", - "SystemAssigned", "UserAssigned", "SystemAssigned,UserAssigned". + "SystemAssigned", "UserAssigned", and "SystemAssigned,UserAssigned". :vartype type: str or ~azure.mgmt.sql.models.IdentityType :ivar tenant_id: The Azure Active Directory tenant id. :vartype tenant_id: str """ _validation = { - 'principal_id': {'readonly': True}, - 'tenant_id': {'readonly': True}, + "principal_id": {"readonly": True}, + "tenant_id": {"readonly": True}, } _attribute_map = { - 'user_assigned_identities': {'key': 'userAssignedIdentities', 'type': '{UserIdentity}'}, - 'principal_id': {'key': 'principalId', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'tenant_id': {'key': 'tenantId', 'type': 'str'}, + "user_assigned_identities": {"key": "userAssignedIdentities", "type": "{UserIdentity}"}, + "principal_id": {"key": "principalId", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "tenant_id": {"key": "tenantId", "type": "str"}, } def __init__( @@ -14785,48 +14637,43 @@ def __init__( :paramtype user_assigned_identities: dict[str, ~azure.mgmt.sql.models.UserIdentity] :keyword type: The identity type. Set this to 'SystemAssigned' in order to automatically create and assign an Azure Active Directory principal for the resource. Known values are: "None", - "SystemAssigned", "UserAssigned", "SystemAssigned,UserAssigned". + "SystemAssigned", "UserAssigned", and "SystemAssigned,UserAssigned". :paramtype type: str or ~azure.mgmt.sql.models.IdentityType """ - super(ResourceIdentity, self).__init__(**kwargs) + super().__init__(**kwargs) self.user_assigned_identities = user_assigned_identities self.principal_id = None self.type = type self.tenant_id = None -class ResourceMoveDefinition(msrest.serialization.Model): +class ResourceMoveDefinition(_serialization.Model): """Contains the information necessary to perform a resource move (rename). All required parameters must be populated in order to send to Azure. - :ivar id: Required. The target ID for the resource. + :ivar id: The target ID for the resource. Required. :vartype id: str """ _validation = { - 'id': {'required': True}, + "id": {"required": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, } - def __init__( - self, - *, - id: str, - **kwargs - ): + def __init__(self, *, id: str, **kwargs): # pylint: disable=redefined-builtin """ - :keyword id: Required. The target ID for the resource. + :keyword id: The target ID for the resource. Required. :paramtype id: str """ - super(ResourceMoveDefinition, self).__init__(**kwargs) + super().__init__(**kwargs) self.id = id -class RestorableDroppedDatabase(ProxyResource): +class RestorableDroppedDatabase(ProxyResource): # pylint: disable=too-many-instance-attributes """A restorable dropped database resource. Variables are only populated by the server, and will be ignored when sending a request. @@ -14841,12 +14688,12 @@ class RestorableDroppedDatabase(ProxyResource): :vartype sku: ~azure.mgmt.sql.models.Sku :ivar location: Resource location. :vartype location: str - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar database_name: The name of the database. :vartype database_name: str :ivar max_size_bytes: The max size of the database expressed in bytes. - :vartype max_size_bytes: long + :vartype max_size_bytes: int :ivar creation_date: The creation date of the database (ISO8601 format). :vartype creation_date: ~datetime.datetime :ivar deletion_date: The deletion date of the database (ISO8601 format). @@ -14854,35 +14701,35 @@ class RestorableDroppedDatabase(ProxyResource): :ivar earliest_restore_date: The earliest restore date of the database (ISO8601 format). :vartype earliest_restore_date: ~datetime.datetime :ivar backup_storage_redundancy: The storage account type used to store backups for this - database. Known values are: "Geo", "Local", "Zone", "GeoZone". + database. Known values are: "Geo", "Local", "Zone", and "GeoZone". :vartype backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'database_name': {'readonly': True}, - 'max_size_bytes': {'readonly': True}, - 'creation_date': {'readonly': True}, - 'deletion_date': {'readonly': True}, - 'earliest_restore_date': {'readonly': True}, - 'backup_storage_redundancy': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "database_name": {"readonly": True}, + "max_size_bytes": {"readonly": True}, + "creation_date": {"readonly": True}, + "deletion_date": {"readonly": True}, + "earliest_restore_date": {"readonly": True}, + "backup_storage_redundancy": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'sku': {'key': 'sku', 'type': 'Sku'}, - 'location': {'key': 'location', 'type': 'str'}, - 'tags': {'key': 'tags', 'type': '{str}'}, - 'database_name': {'key': 'properties.databaseName', 'type': 'str'}, - 'max_size_bytes': {'key': 'properties.maxSizeBytes', 'type': 'long'}, - 'creation_date': {'key': 'properties.creationDate', 'type': 'iso-8601'}, - 'deletion_date': {'key': 'properties.deletionDate', 'type': 'iso-8601'}, - 'earliest_restore_date': {'key': 'properties.earliestRestoreDate', 'type': 'iso-8601'}, - 'backup_storage_redundancy': {'key': 'properties.backupStorageRedundancy', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "sku": {"key": "sku", "type": "Sku"}, + "location": {"key": "location", "type": "str"}, + "tags": {"key": "tags", "type": "{str}"}, + "database_name": {"key": "properties.databaseName", "type": "str"}, + "max_size_bytes": {"key": "properties.maxSizeBytes", "type": "int"}, + "creation_date": {"key": "properties.creationDate", "type": "iso-8601"}, + "deletion_date": {"key": "properties.deletionDate", "type": "iso-8601"}, + "earliest_restore_date": {"key": "properties.earliestRestoreDate", "type": "iso-8601"}, + "backup_storage_redundancy": {"key": "properties.backupStorageRedundancy", "type": "str"}, } def __init__( @@ -14898,10 +14745,10 @@ def __init__( :paramtype sku: ~azure.mgmt.sql.models.Sku :keyword location: Resource location. :paramtype location: str - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] """ - super(RestorableDroppedDatabase, self).__init__(**kwargs) + super().__init__(**kwargs) self.sku = sku self.location = location self.tags = tags @@ -14913,7 +14760,7 @@ def __init__( self.backup_storage_redundancy = None -class RestorableDroppedDatabaseListResult(msrest.serialization.Model): +class RestorableDroppedDatabaseListResult(_serialization.Model): """A list of restorable dropped databases. Variables are only populated by the server, and will be ignored when sending a request. @@ -14925,22 +14772,18 @@ class RestorableDroppedDatabaseListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[RestorableDroppedDatabase]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[RestorableDroppedDatabase]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(RestorableDroppedDatabaseListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -14958,9 +14801,9 @@ class RestorableDroppedManagedDatabase(TrackedResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar location: Required. Resource location. + :ivar location: Resource location. Required. :vartype location: str - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar database_name: The name of the database. :vartype database_name: str @@ -14973,49 +14816,43 @@ class RestorableDroppedManagedDatabase(TrackedResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'location': {'required': True}, - 'database_name': {'readonly': True}, - 'creation_date': {'readonly': True}, - 'deletion_date': {'readonly': True}, - 'earliest_restore_date': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "location": {"required": True}, + "database_name": {"readonly": True}, + "creation_date": {"readonly": True}, + "deletion_date": {"readonly": True}, + "earliest_restore_date": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'tags': {'key': 'tags', 'type': '{str}'}, - 'database_name': {'key': 'properties.databaseName', 'type': 'str'}, - 'creation_date': {'key': 'properties.creationDate', 'type': 'iso-8601'}, - 'deletion_date': {'key': 'properties.deletionDate', 'type': 'iso-8601'}, - 'earliest_restore_date': {'key': 'properties.earliestRestoreDate', 'type': 'iso-8601'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "tags": {"key": "tags", "type": "{str}"}, + "database_name": {"key": "properties.databaseName", "type": "str"}, + "creation_date": {"key": "properties.creationDate", "type": "iso-8601"}, + "deletion_date": {"key": "properties.deletionDate", "type": "iso-8601"}, + "earliest_restore_date": {"key": "properties.earliestRestoreDate", "type": "iso-8601"}, } - def __init__( - self, - *, - location: str, - tags: Optional[Dict[str, str]] = None, - **kwargs - ): + def __init__(self, *, location: str, tags: Optional[Dict[str, str]] = None, **kwargs): """ - :keyword location: Required. Resource location. + :keyword location: Resource location. Required. :paramtype location: str - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] """ - super(RestorableDroppedManagedDatabase, self).__init__(location=location, tags=tags, **kwargs) + super().__init__(location=location, tags=tags, **kwargs) self.database_name = None self.creation_date = None self.deletion_date = None self.earliest_restore_date = None -class RestorableDroppedManagedDatabaseListResult(msrest.serialization.Model): +class RestorableDroppedManagedDatabaseListResult(_serialization.Model): """A list of restorable dropped managed databases. Variables are only populated by the server, and will be ignored when sending a request. @@ -15027,22 +14864,18 @@ class RestorableDroppedManagedDatabaseListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[RestorableDroppedManagedDatabase]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[RestorableDroppedManagedDatabase]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(RestorableDroppedManagedDatabaseListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -15060,7 +14893,7 @@ class RestorePoint(ProxyResource): :vartype type: str :ivar location: Resource location. :vartype location: str - :ivar restore_point_type: The type of restore point. Known values are: "CONTINUOUS", + :ivar restore_point_type: The type of restore point. Known values are: "CONTINUOUS" and "DISCRETE". :vartype restore_point_type: str or ~azure.mgmt.sql.models.RestorePointType :ivar earliest_restore_date: The earliest time to which this database can be restored. @@ -15072,34 +14905,30 @@ class RestorePoint(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'location': {'readonly': True}, - 'restore_point_type': {'readonly': True}, - 'earliest_restore_date': {'readonly': True}, - 'restore_point_creation_date': {'readonly': True}, - 'restore_point_label': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "location": {"readonly": True}, + "restore_point_type": {"readonly": True}, + "earliest_restore_date": {"readonly": True}, + "restore_point_creation_date": {"readonly": True}, + "restore_point_label": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'restore_point_type': {'key': 'properties.restorePointType', 'type': 'str'}, - 'earliest_restore_date': {'key': 'properties.earliestRestoreDate', 'type': 'iso-8601'}, - 'restore_point_creation_date': {'key': 'properties.restorePointCreationDate', 'type': 'iso-8601'}, - 'restore_point_label': {'key': 'properties.restorePointLabel', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "restore_point_type": {"key": "properties.restorePointType", "type": "str"}, + "earliest_restore_date": {"key": "properties.earliestRestoreDate", "type": "iso-8601"}, + "restore_point_creation_date": {"key": "properties.restorePointCreationDate", "type": "iso-8601"}, + "restore_point_label": {"key": "properties.restorePointLabel", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(RestorePoint, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.location = None self.restore_point_type = None self.earliest_restore_date = None @@ -15107,7 +14936,7 @@ def __init__( self.restore_point_label = None -class RestorePointListResult(msrest.serialization.Model): +class RestorePointListResult(_serialization.Model): """A list of long term retention backups. Variables are only populated by the server, and will be ignored when sending a request. @@ -15119,27 +14948,23 @@ class RestorePointListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[RestorePoint]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[RestorePoint]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(RestorePointListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class SecurityEvent(ProxyResource): +class SecurityEvent(ProxyResource): # pylint: disable=too-many-instance-attributes """A security event. Variables are only populated by the server, and will be ignored when sending a request. @@ -15153,7 +14978,7 @@ class SecurityEvent(ProxyResource): :ivar event_time: The time when the security event occurred. :vartype event_time: ~datetime.datetime :ivar security_event_type: The type of the security event. Known values are: "Undefined", - "SqlInjectionVulnerability", "SqlInjectionExploit". + "SqlInjectionVulnerability", and "SqlInjectionExploit". :vartype security_event_type: str or ~azure.mgmt.sql.models.SecurityEventType :ivar subscription: The subscription name. :vartype subscription: str @@ -15174,42 +14999,41 @@ class SecurityEvent(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'event_time': {'readonly': True}, - 'security_event_type': {'readonly': True}, - 'subscription': {'readonly': True}, - 'server': {'readonly': True}, - 'database': {'readonly': True}, - 'client_ip': {'readonly': True}, - 'application_name': {'readonly': True}, - 'principal_name': {'readonly': True}, - 'security_event_sql_injection_additional_properties': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'event_time': {'key': 'properties.eventTime', 'type': 'iso-8601'}, - 'security_event_type': {'key': 'properties.securityEventType', 'type': 'str'}, - 'subscription': {'key': 'properties.subscription', 'type': 'str'}, - 'server': {'key': 'properties.server', 'type': 'str'}, - 'database': {'key': 'properties.database', 'type': 'str'}, - 'client_ip': {'key': 'properties.clientIp', 'type': 'str'}, - 'application_name': {'key': 'properties.applicationName', 'type': 'str'}, - 'principal_name': {'key': 'properties.principalName', 'type': 'str'}, - 'security_event_sql_injection_additional_properties': {'key': 'properties.securityEventSqlInjectionAdditionalProperties', 'type': 'SecurityEventSqlInjectionAdditionalProperties'}, - } - - def __init__( - self, - **kwargs - ): - """ - """ - super(SecurityEvent, self).__init__(**kwargs) + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "event_time": {"readonly": True}, + "security_event_type": {"readonly": True}, + "subscription": {"readonly": True}, + "server": {"readonly": True}, + "database": {"readonly": True}, + "client_ip": {"readonly": True}, + "application_name": {"readonly": True}, + "principal_name": {"readonly": True}, + "security_event_sql_injection_additional_properties": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "event_time": {"key": "properties.eventTime", "type": "iso-8601"}, + "security_event_type": {"key": "properties.securityEventType", "type": "str"}, + "subscription": {"key": "properties.subscription", "type": "str"}, + "server": {"key": "properties.server", "type": "str"}, + "database": {"key": "properties.database", "type": "str"}, + "client_ip": {"key": "properties.clientIp", "type": "str"}, + "application_name": {"key": "properties.applicationName", "type": "str"}, + "principal_name": {"key": "properties.principalName", "type": "str"}, + "security_event_sql_injection_additional_properties": { + "key": "properties.securityEventSqlInjectionAdditionalProperties", + "type": "SecurityEventSqlInjectionAdditionalProperties", + }, + } + + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.event_time = None self.security_event_type = None self.subscription = None @@ -15221,7 +15045,7 @@ def __init__( self.security_event_sql_injection_additional_properties = None -class SecurityEventCollection(msrest.serialization.Model): +class SecurityEventCollection(_serialization.Model): """A list of security events. Variables are only populated by the server, and will be ignored when sending a request. @@ -15233,27 +15057,23 @@ class SecurityEventCollection(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[SecurityEvent]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[SecurityEvent]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SecurityEventCollection, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class SecurityEventsFilterParameters(msrest.serialization.Model): +class SecurityEventsFilterParameters(_serialization.Model): """The properties that are supported in the $filter operation. :ivar event_time: Filter on the event time. @@ -15263,16 +15083,12 @@ class SecurityEventsFilterParameters(msrest.serialization.Model): """ _attribute_map = { - 'event_time': {'key': 'eventTime', 'type': 'iso-8601'}, - 'show_server_records': {'key': 'showServerRecords', 'type': 'bool'}, + "event_time": {"key": "eventTime", "type": "iso-8601"}, + "show_server_records": {"key": "showServerRecords", "type": "bool"}, } def __init__( - self, - *, - event_time: Optional[datetime.datetime] = None, - show_server_records: Optional[bool] = None, - **kwargs + self, *, event_time: Optional[datetime.datetime] = None, show_server_records: Optional[bool] = None, **kwargs ): """ :keyword event_time: Filter on the event time. @@ -15280,12 +15096,12 @@ def __init__( :keyword show_server_records: Whether to show server records or not. :paramtype show_server_records: bool """ - super(SecurityEventsFilterParameters, self).__init__(**kwargs) + super().__init__(**kwargs) self.event_time = event_time self.show_server_records = show_server_records -class SecurityEventSqlInjectionAdditionalProperties(msrest.serialization.Model): +class SecurityEventSqlInjectionAdditionalProperties(_serialization.Model): """The properties of a security event sql injection additional properties. Variables are only populated by the server, and will be ignored when sending a request. @@ -15307,32 +15123,28 @@ class SecurityEventSqlInjectionAdditionalProperties(msrest.serialization.Model): """ _validation = { - 'threat_id': {'readonly': True}, - 'statement': {'readonly': True}, - 'statement_highlight_offset': {'readonly': True}, - 'statement_highlight_length': {'readonly': True}, - 'error_code': {'readonly': True}, - 'error_severity': {'readonly': True}, - 'error_message': {'readonly': True}, + "threat_id": {"readonly": True}, + "statement": {"readonly": True}, + "statement_highlight_offset": {"readonly": True}, + "statement_highlight_length": {"readonly": True}, + "error_code": {"readonly": True}, + "error_severity": {"readonly": True}, + "error_message": {"readonly": True}, } _attribute_map = { - 'threat_id': {'key': 'threatId', 'type': 'str'}, - 'statement': {'key': 'statement', 'type': 'str'}, - 'statement_highlight_offset': {'key': 'statementHighlightOffset', 'type': 'int'}, - 'statement_highlight_length': {'key': 'statementHighlightLength', 'type': 'int'}, - 'error_code': {'key': 'errorCode', 'type': 'int'}, - 'error_severity': {'key': 'errorSeverity', 'type': 'int'}, - 'error_message': {'key': 'errorMessage', 'type': 'str'}, + "threat_id": {"key": "threatId", "type": "str"}, + "statement": {"key": "statement", "type": "str"}, + "statement_highlight_offset": {"key": "statementHighlightOffset", "type": "int"}, + "statement_highlight_length": {"key": "statementHighlightLength", "type": "int"}, + "error_code": {"key": "errorCode", "type": "int"}, + "error_severity": {"key": "errorSeverity", "type": "int"}, + "error_message": {"key": "errorMessage", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SecurityEventSqlInjectionAdditionalProperties, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.threat_id = None self.statement = None self.statement_highlight_offset = None @@ -15342,7 +15154,7 @@ def __init__( self.error_message = None -class SensitivityLabel(ProxyResource): +class SensitivityLabel(ProxyResource): # pylint: disable=too-many-instance-attributes """A sensitivity label. Variables are only populated by the server, and will be ignored when sending a request. @@ -15373,35 +15185,35 @@ class SensitivityLabel(ProxyResource): sensitivity label only. Specifies whether the sensitivity recommendation on this column is disabled (dismissed) or not. :vartype is_disabled: bool - :ivar rank: Known values are: "None", "Low", "Medium", "High", "Critical". + :ivar rank: Known values are: "None", "Low", "Medium", "High", and "Critical". :vartype rank: str or ~azure.mgmt.sql.models.SensitivityLabelRank """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'managed_by': {'readonly': True}, - 'schema_name': {'readonly': True}, - 'table_name': {'readonly': True}, - 'column_name': {'readonly': True}, - 'is_disabled': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "managed_by": {"readonly": True}, + "schema_name": {"readonly": True}, + "table_name": {"readonly": True}, + "column_name": {"readonly": True}, + "is_disabled": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'managed_by': {'key': 'managedBy', 'type': 'str'}, - 'schema_name': {'key': 'properties.schemaName', 'type': 'str'}, - 'table_name': {'key': 'properties.tableName', 'type': 'str'}, - 'column_name': {'key': 'properties.columnName', 'type': 'str'}, - 'label_name': {'key': 'properties.labelName', 'type': 'str'}, - 'label_id': {'key': 'properties.labelId', 'type': 'str'}, - 'information_type': {'key': 'properties.informationType', 'type': 'str'}, - 'information_type_id': {'key': 'properties.informationTypeId', 'type': 'str'}, - 'is_disabled': {'key': 'properties.isDisabled', 'type': 'bool'}, - 'rank': {'key': 'properties.rank', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "managed_by": {"key": "managedBy", "type": "str"}, + "schema_name": {"key": "properties.schemaName", "type": "str"}, + "table_name": {"key": "properties.tableName", "type": "str"}, + "column_name": {"key": "properties.columnName", "type": "str"}, + "label_name": {"key": "properties.labelName", "type": "str"}, + "label_id": {"key": "properties.labelId", "type": "str"}, + "information_type": {"key": "properties.informationType", "type": "str"}, + "information_type_id": {"key": "properties.informationTypeId", "type": "str"}, + "is_disabled": {"key": "properties.isDisabled", "type": "bool"}, + "rank": {"key": "properties.rank", "type": "str"}, } def __init__( @@ -15423,10 +15235,10 @@ def __init__( :paramtype information_type: str :keyword information_type_id: The information type ID. :paramtype information_type_id: str - :keyword rank: Known values are: "None", "Low", "Medium", "High", "Critical". + :keyword rank: Known values are: "None", "Low", "Medium", "High", and "Critical". :paramtype rank: str or ~azure.mgmt.sql.models.SensitivityLabelRank """ - super(SensitivityLabel, self).__init__(**kwargs) + super().__init__(**kwargs) self.managed_by = None self.schema_name = None self.table_name = None @@ -15439,7 +15251,7 @@ def __init__( self.rank = rank -class SensitivityLabelListResult(msrest.serialization.Model): +class SensitivityLabelListResult(_serialization.Model): """A list of sensitivity labels. Variables are only populated by the server, and will be ignored when sending a request. @@ -15451,22 +15263,18 @@ class SensitivityLabelListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[SensitivityLabel]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[SensitivityLabel]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SensitivityLabelListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -15482,7 +15290,7 @@ class SensitivityLabelUpdate(ProxyResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar op: Known values are: "set", "remove". + :ivar op: Known values are: "set" and "remove". :vartype op: str or ~azure.mgmt.sql.models.SensitivityLabelUpdateKind :ivar schema: Schema name of the column to update. :vartype schema: str @@ -15495,20 +15303,20 @@ class SensitivityLabelUpdate(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'op': {'key': 'properties.op', 'type': 'str'}, - 'schema': {'key': 'properties.schema', 'type': 'str'}, - 'table': {'key': 'properties.table', 'type': 'str'}, - 'column': {'key': 'properties.column', 'type': 'str'}, - 'sensitivity_label': {'key': 'properties.sensitivityLabel', 'type': 'SensitivityLabel'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "op": {"key": "properties.op", "type": "str"}, + "schema": {"key": "properties.schema", "type": "str"}, + "table": {"key": "properties.table", "type": "str"}, + "column": {"key": "properties.column", "type": "str"}, + "sensitivity_label": {"key": "properties.sensitivityLabel", "type": "SensitivityLabel"}, } def __init__( @@ -15522,7 +15330,7 @@ def __init__( **kwargs ): """ - :keyword op: Known values are: "set", "remove". + :keyword op: Known values are: "set" and "remove". :paramtype op: str or ~azure.mgmt.sql.models.SensitivityLabelUpdateKind :keyword schema: Schema name of the column to update. :paramtype schema: str @@ -15533,7 +15341,7 @@ def __init__( :keyword sensitivity_label: The sensitivity label information to apply on a column. :paramtype sensitivity_label: ~azure.mgmt.sql.models.SensitivityLabel """ - super(SensitivityLabelUpdate, self).__init__(**kwargs) + super().__init__(**kwargs) self.op = op self.schema = schema self.table = table @@ -15541,7 +15349,7 @@ def __init__( self.sensitivity_label = sensitivity_label -class SensitivityLabelUpdateList(msrest.serialization.Model): +class SensitivityLabelUpdateList(_serialization.Model): """A list of sensitivity label update operations. :ivar operations: @@ -15549,24 +15357,19 @@ class SensitivityLabelUpdateList(msrest.serialization.Model): """ _attribute_map = { - 'operations': {'key': 'operations', 'type': '[SensitivityLabelUpdate]'}, + "operations": {"key": "operations", "type": "[SensitivityLabelUpdate]"}, } - def __init__( - self, - *, - operations: Optional[List["_models.SensitivityLabelUpdate"]] = None, - **kwargs - ): + def __init__(self, *, operations: Optional[List["_models.SensitivityLabelUpdate"]] = None, **kwargs): """ :keyword operations: :paramtype operations: list[~azure.mgmt.sql.models.SensitivityLabelUpdate] """ - super(SensitivityLabelUpdateList, self).__init__(**kwargs) + super().__init__(**kwargs) self.operations = operations -class Server(TrackedResource): +class Server(TrackedResource): # pylint: disable=too-many-instance-attributes """An Azure SQL Database server. Variables are only populated by the server, and will be ignored when sending a request. @@ -15579,9 +15382,9 @@ class Server(TrackedResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar location: Required. Resource location. + :ivar location: Resource location. Required. :vartype location: str - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar identity: The Azure Active Directory identity of the server. :vartype identity: ~azure.mgmt.sql.models.ResourceIdentity @@ -15606,10 +15409,10 @@ class Server(TrackedResource): :vartype minimal_tls_version: str :ivar public_network_access: Whether or not public endpoint access is allowed for this server. Value is optional but if passed in, must be 'Enabled' or 'Disabled'. Known values are: - "Enabled", "Disabled". + "Enabled" and "Disabled". :vartype public_network_access: str or ~azure.mgmt.sql.models.ServerNetworkAccessFlag :ivar workspace_feature: Whether or not existing server has a workspace created and if it - allows connection from workspace. Known values are: "Connected", "Disconnected". + allows connection from workspace. Known values are: "Connected" and "Disconnected". :vartype workspace_feature: str or ~azure.mgmt.sql.models.ServerWorkspaceFeature :ivar primary_user_assigned_identity_id: The resource id of a user assigned identity to be used by default. @@ -15622,45 +15425,48 @@ class Server(TrackedResource): :vartype administrators: ~azure.mgmt.sql.models.ServerExternalAdministrator :ivar restrict_outbound_network_access: Whether or not to restrict outbound network access for this server. Value is optional but if passed in, must be 'Enabled' or 'Disabled'. Known values - are: "Enabled", "Disabled". + are: "Enabled" and "Disabled". :vartype restrict_outbound_network_access: str or ~azure.mgmt.sql.models.ServerNetworkAccessFlag """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'location': {'required': True}, - 'kind': {'readonly': True}, - 'state': {'readonly': True}, - 'fully_qualified_domain_name': {'readonly': True}, - 'private_endpoint_connections': {'readonly': True}, - 'workspace_feature': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'tags': {'key': 'tags', 'type': '{str}'}, - 'identity': {'key': 'identity', 'type': 'ResourceIdentity'}, - 'kind': {'key': 'kind', 'type': 'str'}, - 'administrator_login': {'key': 'properties.administratorLogin', 'type': 'str'}, - 'administrator_login_password': {'key': 'properties.administratorLoginPassword', 'type': 'str'}, - 'version': {'key': 'properties.version', 'type': 'str'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'fully_qualified_domain_name': {'key': 'properties.fullyQualifiedDomainName', 'type': 'str'}, - 'private_endpoint_connections': {'key': 'properties.privateEndpointConnections', 'type': '[ServerPrivateEndpointConnection]'}, - 'minimal_tls_version': {'key': 'properties.minimalTlsVersion', 'type': 'str'}, - 'public_network_access': {'key': 'properties.publicNetworkAccess', 'type': 'str'}, - 'workspace_feature': {'key': 'properties.workspaceFeature', 'type': 'str'}, - 'primary_user_assigned_identity_id': {'key': 'properties.primaryUserAssignedIdentityId', 'type': 'str'}, - 'federated_client_id': {'key': 'properties.federatedClientId', 'type': 'str'}, - 'key_id': {'key': 'properties.keyId', 'type': 'str'}, - 'administrators': {'key': 'properties.administrators', 'type': 'ServerExternalAdministrator'}, - 'restrict_outbound_network_access': {'key': 'properties.restrictOutboundNetworkAccess', 'type': 'str'}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "location": {"required": True}, + "kind": {"readonly": True}, + "state": {"readonly": True}, + "fully_qualified_domain_name": {"readonly": True}, + "private_endpoint_connections": {"readonly": True}, + "workspace_feature": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "tags": {"key": "tags", "type": "{str}"}, + "identity": {"key": "identity", "type": "ResourceIdentity"}, + "kind": {"key": "kind", "type": "str"}, + "administrator_login": {"key": "properties.administratorLogin", "type": "str"}, + "administrator_login_password": {"key": "properties.administratorLoginPassword", "type": "str"}, + "version": {"key": "properties.version", "type": "str"}, + "state": {"key": "properties.state", "type": "str"}, + "fully_qualified_domain_name": {"key": "properties.fullyQualifiedDomainName", "type": "str"}, + "private_endpoint_connections": { + "key": "properties.privateEndpointConnections", + "type": "[ServerPrivateEndpointConnection]", + }, + "minimal_tls_version": {"key": "properties.minimalTlsVersion", "type": "str"}, + "public_network_access": {"key": "properties.publicNetworkAccess", "type": "str"}, + "workspace_feature": {"key": "properties.workspaceFeature", "type": "str"}, + "primary_user_assigned_identity_id": {"key": "properties.primaryUserAssignedIdentityId", "type": "str"}, + "federated_client_id": {"key": "properties.federatedClientId", "type": "str"}, + "key_id": {"key": "properties.keyId", "type": "str"}, + "administrators": {"key": "properties.administrators", "type": "ServerExternalAdministrator"}, + "restrict_outbound_network_access": {"key": "properties.restrictOutboundNetworkAccess", "type": "str"}, } def __init__( @@ -15682,9 +15488,9 @@ def __init__( **kwargs ): """ - :keyword location: Required. Resource location. + :keyword location: Resource location. Required. :paramtype location: str - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] :keyword identity: The Azure Active Directory identity of the server. :paramtype identity: ~azure.mgmt.sql.models.ResourceIdentity @@ -15700,7 +15506,7 @@ def __init__( :paramtype minimal_tls_version: str :keyword public_network_access: Whether or not public endpoint access is allowed for this server. Value is optional but if passed in, must be 'Enabled' or 'Disabled'. Known values are: - "Enabled", "Disabled". + "Enabled" and "Disabled". :paramtype public_network_access: str or ~azure.mgmt.sql.models.ServerNetworkAccessFlag :keyword primary_user_assigned_identity_id: The resource id of a user assigned identity to be used by default. @@ -15713,11 +15519,11 @@ def __init__( :paramtype administrators: ~azure.mgmt.sql.models.ServerExternalAdministrator :keyword restrict_outbound_network_access: Whether or not to restrict outbound network access for this server. Value is optional but if passed in, must be 'Enabled' or 'Disabled'. Known - values are: "Enabled", "Disabled". + values are: "Enabled" and "Disabled". :paramtype restrict_outbound_network_access: str or ~azure.mgmt.sql.models.ServerNetworkAccessFlag """ - super(Server, self).__init__(location=location, tags=tags, **kwargs) + super().__init__(location=location, tags=tags, **kwargs) self.identity = identity self.kind = None self.administrator_login = administrator_login @@ -15751,42 +15557,37 @@ class ServerAdvancedThreatProtection(ProxyResource): :vartype system_data: ~azure.mgmt.sql.models.SystemData :ivar state: Specifies the state of the Advanced Threat Protection, whether it is enabled or disabled or a state has not been applied yet on the specific database or server. Known values - are: "New", "Enabled", "Disabled". + are: "New", "Enabled", and "Disabled". :vartype state: str or ~azure.mgmt.sql.models.AdvancedThreatProtectionState :ivar creation_time: Specifies the UTC creation time of the policy. :vartype creation_time: ~datetime.datetime """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'system_data': {'readonly': True}, - 'creation_time': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "system_data": {"readonly": True}, + "creation_time": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'system_data': {'key': 'systemData', 'type': 'SystemData'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'creation_time': {'key': 'properties.creationTime', 'type': 'iso-8601'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "system_data": {"key": "systemData", "type": "SystemData"}, + "state": {"key": "properties.state", "type": "str"}, + "creation_time": {"key": "properties.creationTime", "type": "iso-8601"}, } - def __init__( - self, - *, - state: Optional[Union[str, "_models.AdvancedThreatProtectionState"]] = None, - **kwargs - ): + def __init__(self, *, state: Optional[Union[str, "_models.AdvancedThreatProtectionState"]] = None, **kwargs): """ :keyword state: Specifies the state of the Advanced Threat Protection, whether it is enabled or disabled or a state has not been applied yet on the specific database or server. Known values - are: "New", "Enabled", "Disabled". + are: "New", "Enabled", and "Disabled". :paramtype state: str or ~azure.mgmt.sql.models.AdvancedThreatProtectionState """ - super(ServerAdvancedThreatProtection, self).__init__(**kwargs) + super().__init__(**kwargs) self.system_data = None self.state = state self.creation_time = None @@ -15803,10 +15604,10 @@ class ServerAutomaticTuning(ProxyResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar desired_state: Automatic tuning desired state. Known values are: "Custom", "Auto", + :ivar desired_state: Automatic tuning desired state. Known values are: "Custom", "Auto", and "Unspecified". :vartype desired_state: str or ~azure.mgmt.sql.models.AutomaticTuningServerMode - :ivar actual_state: Automatic tuning actual state. Known values are: "Custom", "Auto", + :ivar actual_state: Automatic tuning actual state. Known values are: "Custom", "Auto", and "Unspecified". :vartype actual_state: str or ~azure.mgmt.sql.models.AutomaticTuningServerMode :ivar options: Automatic tuning options definition. @@ -15814,19 +15615,19 @@ class ServerAutomaticTuning(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'actual_state': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "actual_state": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'desired_state': {'key': 'properties.desiredState', 'type': 'str'}, - 'actual_state': {'key': 'properties.actualState', 'type': 'str'}, - 'options': {'key': 'properties.options', 'type': '{AutomaticTuningServerOptions}'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "desired_state": {"key": "properties.desiredState", "type": "str"}, + "actual_state": {"key": "properties.actualState", "type": "str"}, + "options": {"key": "properties.options", "type": "{AutomaticTuningServerOptions}"}, } def __init__( @@ -15837,13 +15638,13 @@ def __init__( **kwargs ): """ - :keyword desired_state: Automatic tuning desired state. Known values are: "Custom", "Auto", + :keyword desired_state: Automatic tuning desired state. Known values are: "Custom", "Auto", and "Unspecified". :paramtype desired_state: str or ~azure.mgmt.sql.models.AutomaticTuningServerMode :keyword options: Automatic tuning options definition. :paramtype options: dict[str, ~azure.mgmt.sql.models.AutomaticTuningServerOptions] """ - super(ServerAutomaticTuning, self).__init__(**kwargs) + super().__init__(**kwargs) self.desired_state = desired_state self.actual_state = None self.options = options @@ -15860,7 +15661,7 @@ class ServerAzureADAdministrator(ProxyResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar administrator_type: Type of the sever administrator. Known values are: "ActiveDirectory". + :ivar administrator_type: Type of the sever administrator. "ActiveDirectory" :vartype administrator_type: str or ~azure.mgmt.sql.models.AdministratorType :ivar login: Login name of the server administrator. :vartype login: str @@ -15873,21 +15674,21 @@ class ServerAzureADAdministrator(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'azure_ad_only_authentication': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "azure_ad_only_authentication": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'administrator_type': {'key': 'properties.administratorType', 'type': 'str'}, - 'login': {'key': 'properties.login', 'type': 'str'}, - 'sid': {'key': 'properties.sid', 'type': 'str'}, - 'tenant_id': {'key': 'properties.tenantId', 'type': 'str'}, - 'azure_ad_only_authentication': {'key': 'properties.azureADOnlyAuthentication', 'type': 'bool'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "administrator_type": {"key": "properties.administratorType", "type": "str"}, + "login": {"key": "properties.login", "type": "str"}, + "sid": {"key": "properties.sid", "type": "str"}, + "tenant_id": {"key": "properties.tenantId", "type": "str"}, + "azure_ad_only_authentication": {"key": "properties.azureADOnlyAuthentication", "type": "bool"}, } def __init__( @@ -15900,8 +15701,7 @@ def __init__( **kwargs ): """ - :keyword administrator_type: Type of the sever administrator. Known values are: - "ActiveDirectory". + :keyword administrator_type: Type of the sever administrator. "ActiveDirectory" :paramtype administrator_type: str or ~azure.mgmt.sql.models.AdministratorType :keyword login: Login name of the server administrator. :paramtype login: str @@ -15910,7 +15710,7 @@ def __init__( :keyword tenant_id: Tenant ID of the administrator. :paramtype tenant_id: str """ - super(ServerAzureADAdministrator, self).__init__(**kwargs) + super().__init__(**kwargs) self.administrator_type = administrator_type self.login = login self.sid = sid @@ -15934,33 +15734,28 @@ class ServerAzureADOnlyAuthentication(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'azure_ad_only_authentication': {'key': 'properties.azureADOnlyAuthentication', 'type': 'bool'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "azure_ad_only_authentication": {"key": "properties.azureADOnlyAuthentication", "type": "bool"}, } - def __init__( - self, - *, - azure_ad_only_authentication: Optional[bool] = None, - **kwargs - ): + def __init__(self, *, azure_ad_only_authentication: Optional[bool] = None, **kwargs): """ :keyword azure_ad_only_authentication: Azure Active Directory only Authentication enabled. :paramtype azure_ad_only_authentication: bool """ - super(ServerAzureADOnlyAuthentication, self).__init__(**kwargs) + super().__init__(**kwargs) self.azure_ad_only_authentication = azure_ad_only_authentication -class ServerBlobAuditingPolicy(ProxyResource): +class ServerBlobAuditingPolicy(ProxyResource): # pylint: disable=too-many-instance-attributes """A server blob auditing policy. Variables are only populated by the server, and will be ignored when sending a request. @@ -15975,14 +15770,14 @@ class ServerBlobAuditingPolicy(ProxyResource): logs will be sent to Azure Monitor. In order to send the events to Azure Monitor, specify 'State' as 'Enabled', 'IsAzureMonitorTargetEnabled' as true and 'IsDevopsAuditEnabled' as true - + When using REST API to configure auditing, Diagnostic Settings with 'DevOpsOperationsAudit' diagnostic logs category on the master database should also be created. - + Diagnostic Settings URI format: PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/master/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview - + For more information, see `Diagnostic Settings REST API `_ or `Diagnostic Settings PowerShell `_. @@ -15991,21 +15786,21 @@ class ServerBlobAuditingPolicy(ProxyResource): account. :vartype retention_days: int :ivar audit_actions_and_groups: Specifies the Actions-Groups and Actions to audit. - + The recommended set of action groups to use is the following combination - this will audit all the queries and stored procedures executed against the database, as well as successful and failed logins: - + BATCH_COMPLETED_GROUP, SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP, FAILED_DATABASE_AUTHENTICATION_GROUP. - + This above combination is also the set that is configured by default when enabling auditing from the Azure portal. - + The supported action groups to audit are (note: choose only specific groups that cover your auditing needs. Using unnecessary groups could lead to very large quantities of audit records): - + APPLICATION_ROLE_CHANGE_PASSWORD_GROUP BACKUP_RESTORE_GROUP DATABASE_LOGOUT_GROUP @@ -16030,14 +15825,14 @@ class ServerBlobAuditingPolicy(ProxyResource): DATABASE_OWNERSHIP_CHANGE_GROUP DATABASE_CHANGE_GROUP LEDGER_OPERATION_GROUP - + These are groups that cover all sql statements and stored procedures executed against the database, and should not be used in combination with other groups as this will result in duplicate audit logs. - + For more information, see `Database-Level Audit Action Groups `_. - + For Database auditing policy, specific Actions can also be specified (note that Actions cannot be specified for Server auditing policy). The supported actions to audit are: SELECT @@ -16047,19 +15842,19 @@ class ServerBlobAuditingPolicy(ProxyResource): EXECUTE RECEIVE REFERENCES - + The general form for defining an action to be audited is: {action} ON {object} BY {principal} - + Note that :code:`` in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE::{db_name} and SCHEMA::{schema_name} are used, respectively. - + For example: SELECT on dbo.myTable by public SELECT on DATABASE::myDatabase by public SELECT on SCHEMA::mySchema by public - + For more information, see `Database-Level Audit Actions `_. :vartype audit_actions_and_groups: list[str] @@ -16070,15 +15865,15 @@ class ServerBlobAuditingPolicy(ProxyResource): Monitor. In order to send the events to Azure Monitor, specify 'State' as 'Enabled' and 'IsAzureMonitorTargetEnabled' as true. - + When using REST API to configure auditing, Diagnostic Settings with 'SQLSecurityAuditEvents' diagnostic logs category on the database should be also created. Note that for server level audit you should use the 'master' database as {databaseName}. - + Diagnostic Settings URI format: PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview - + For more information, see `Diagnostic Settings REST API `_ or `Diagnostic Settings PowerShell `_. @@ -16091,7 +15886,7 @@ class ServerBlobAuditingPolicy(ProxyResource): storage. :vartype is_managed_identity_in_use: bool :ivar state: Specifies the state of the audit. If state is Enabled, storageEndpoint or - isAzureMonitorTargetEnabled are required. Known values are: "Enabled", "Disabled". + isAzureMonitorTargetEnabled are required. Known values are: "Enabled" and "Disabled". :vartype state: str or ~azure.mgmt.sql.models.BlobAuditingPolicyState :ivar storage_endpoint: Specifies the blob storage endpoint (e.g. https://MyAccount.blob.core.windows.net). If state is Enabled, storageEndpoint or @@ -16102,8 +15897,8 @@ class ServerBlobAuditingPolicy(ProxyResource): storageAccountAccessKey will use SQL server system-assigned managed identity to access the storage. Prerequisites for using managed identity authentication: - - + + #. Assign SQL Server a system-assigned managed identity in Azure Active Directory (AAD). #. Grant SQL Server identity access to the storage account by adding 'Storage Blob Data Contributor' RBAC role to the server identity. @@ -16115,26 +15910,26 @@ class ServerBlobAuditingPolicy(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'is_devops_audit_enabled': {'key': 'properties.isDevopsAuditEnabled', 'type': 'bool'}, - 'retention_days': {'key': 'properties.retentionDays', 'type': 'int'}, - 'audit_actions_and_groups': {'key': 'properties.auditActionsAndGroups', 'type': '[str]'}, - 'is_storage_secondary_key_in_use': {'key': 'properties.isStorageSecondaryKeyInUse', 'type': 'bool'}, - 'is_azure_monitor_target_enabled': {'key': 'properties.isAzureMonitorTargetEnabled', 'type': 'bool'}, - 'queue_delay_ms': {'key': 'properties.queueDelayMs', 'type': 'int'}, - 'is_managed_identity_in_use': {'key': 'properties.isManagedIdentityInUse', 'type': 'bool'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'storage_endpoint': {'key': 'properties.storageEndpoint', 'type': 'str'}, - 'storage_account_access_key': {'key': 'properties.storageAccountAccessKey', 'type': 'str'}, - 'storage_account_subscription_id': {'key': 'properties.storageAccountSubscriptionId', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "is_devops_audit_enabled": {"key": "properties.isDevopsAuditEnabled", "type": "bool"}, + "retention_days": {"key": "properties.retentionDays", "type": "int"}, + "audit_actions_and_groups": {"key": "properties.auditActionsAndGroups", "type": "[str]"}, + "is_storage_secondary_key_in_use": {"key": "properties.isStorageSecondaryKeyInUse", "type": "bool"}, + "is_azure_monitor_target_enabled": {"key": "properties.isAzureMonitorTargetEnabled", "type": "bool"}, + "queue_delay_ms": {"key": "properties.queueDelayMs", "type": "int"}, + "is_managed_identity_in_use": {"key": "properties.isManagedIdentityInUse", "type": "bool"}, + "state": {"key": "properties.state", "type": "str"}, + "storage_endpoint": {"key": "properties.storageEndpoint", "type": "str"}, + "storage_account_access_key": {"key": "properties.storageAccountAccessKey", "type": "str"}, + "storage_account_subscription_id": {"key": "properties.storageAccountSubscriptionId", "type": "str"}, } def __init__( @@ -16158,14 +15953,14 @@ def __init__( devops logs will be sent to Azure Monitor. In order to send the events to Azure Monitor, specify 'State' as 'Enabled', 'IsAzureMonitorTargetEnabled' as true and 'IsDevopsAuditEnabled' as true - + When using REST API to configure auditing, Diagnostic Settings with 'DevOpsOperationsAudit' diagnostic logs category on the master database should also be created. - + Diagnostic Settings URI format: PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/master/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview - + For more information, see `Diagnostic Settings REST API `_ or `Diagnostic Settings PowerShell `_. @@ -16174,21 +15969,21 @@ def __init__( account. :paramtype retention_days: int :keyword audit_actions_and_groups: Specifies the Actions-Groups and Actions to audit. - + The recommended set of action groups to use is the following combination - this will audit all the queries and stored procedures executed against the database, as well as successful and failed logins: - + BATCH_COMPLETED_GROUP, SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP, FAILED_DATABASE_AUTHENTICATION_GROUP. - + This above combination is also the set that is configured by default when enabling auditing from the Azure portal. - + The supported action groups to audit are (note: choose only specific groups that cover your auditing needs. Using unnecessary groups could lead to very large quantities of audit records): - + APPLICATION_ROLE_CHANGE_PASSWORD_GROUP BACKUP_RESTORE_GROUP DATABASE_LOGOUT_GROUP @@ -16213,14 +16008,14 @@ def __init__( DATABASE_OWNERSHIP_CHANGE_GROUP DATABASE_CHANGE_GROUP LEDGER_OPERATION_GROUP - + These are groups that cover all sql statements and stored procedures executed against the database, and should not be used in combination with other groups as this will result in duplicate audit logs. - + For more information, see `Database-Level Audit Action Groups `_. - + For Database auditing policy, specific Actions can also be specified (note that Actions cannot be specified for Server auditing policy). The supported actions to audit are: SELECT @@ -16230,19 +16025,19 @@ def __init__( EXECUTE RECEIVE REFERENCES - + The general form for defining an action to be audited is: {action} ON {object} BY {principal} - + Note that :code:`` in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE::{db_name} and SCHEMA::{schema_name} are used, respectively. - + For example: SELECT on dbo.myTable by public SELECT on DATABASE::myDatabase by public SELECT on SCHEMA::mySchema by public - + For more information, see `Database-Level Audit Actions `_. :paramtype audit_actions_and_groups: list[str] @@ -16253,15 +16048,15 @@ def __init__( Monitor. In order to send the events to Azure Monitor, specify 'State' as 'Enabled' and 'IsAzureMonitorTargetEnabled' as true. - + When using REST API to configure auditing, Diagnostic Settings with 'SQLSecurityAuditEvents' diagnostic logs category on the database should be also created. Note that for server level audit you should use the 'master' database as {databaseName}. - + Diagnostic Settings URI format: PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview - + For more information, see `Diagnostic Settings REST API `_ or `Diagnostic Settings PowerShell `_. @@ -16274,7 +16069,7 @@ def __init__( storage. :paramtype is_managed_identity_in_use: bool :keyword state: Specifies the state of the audit. If state is Enabled, storageEndpoint or - isAzureMonitorTargetEnabled are required. Known values are: "Enabled", "Disabled". + isAzureMonitorTargetEnabled are required. Known values are: "Enabled" and "Disabled". :paramtype state: str or ~azure.mgmt.sql.models.BlobAuditingPolicyState :keyword storage_endpoint: Specifies the blob storage endpoint (e.g. https://MyAccount.blob.core.windows.net). If state is Enabled, storageEndpoint or @@ -16286,8 +16081,8 @@ def __init__( storageAccountAccessKey will use SQL server system-assigned managed identity to access the storage. Prerequisites for using managed identity authentication: - - + + #. Assign SQL Server a system-assigned managed identity in Azure Active Directory (AAD). #. Grant SQL Server identity access to the storage account by adding 'Storage Blob Data Contributor' RBAC role to the server identity. @@ -16297,7 +16092,7 @@ def __init__( :keyword storage_account_subscription_id: Specifies the blob storage subscription Id. :paramtype storage_account_subscription_id: str """ - super(ServerBlobAuditingPolicy, self).__init__(**kwargs) + super().__init__(**kwargs) self.is_devops_audit_enabled = is_devops_audit_enabled self.retention_days = retention_days self.audit_actions_and_groups = audit_actions_and_groups @@ -16311,7 +16106,7 @@ def __init__( self.storage_account_subscription_id = storage_account_subscription_id -class ServerBlobAuditingPolicyListResult(msrest.serialization.Model): +class ServerBlobAuditingPolicyListResult(_serialization.Model): """A list of server auditing settings. Variables are only populated by the server, and will be ignored when sending a request. @@ -16323,22 +16118,18 @@ class ServerBlobAuditingPolicyListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ServerBlobAuditingPolicy]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ServerBlobAuditingPolicy]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ServerBlobAuditingPolicyListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -16365,42 +16156,37 @@ class ServerCommunicationLink(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'location': {'readonly': True}, - 'kind': {'readonly': True}, - 'state': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "location": {"readonly": True}, + "kind": {"readonly": True}, + "state": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'kind': {'key': 'kind', 'type': 'str'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'partner_server': {'key': 'properties.partnerServer', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "kind": {"key": "kind", "type": "str"}, + "state": {"key": "properties.state", "type": "str"}, + "partner_server": {"key": "properties.partnerServer", "type": "str"}, } - def __init__( - self, - *, - partner_server: Optional[str] = None, - **kwargs - ): + def __init__(self, *, partner_server: Optional[str] = None, **kwargs): """ :keyword partner_server: The name of the partner server. :paramtype partner_server: str """ - super(ServerCommunicationLink, self).__init__(**kwargs) + super().__init__(**kwargs) self.location = None self.kind = None self.state = None self.partner_server = partner_server -class ServerCommunicationLinkListResult(msrest.serialization.Model): +class ServerCommunicationLinkListResult(_serialization.Model): """A list of server communication links. :ivar value: The list of server communication links. @@ -16408,20 +16194,15 @@ class ServerCommunicationLinkListResult(msrest.serialization.Model): """ _attribute_map = { - 'value': {'key': 'value', 'type': '[ServerCommunicationLink]'}, + "value": {"key": "value", "type": "[ServerCommunicationLink]"}, } - def __init__( - self, - *, - value: Optional[List["_models.ServerCommunicationLink"]] = None, - **kwargs - ): + def __init__(self, *, value: Optional[List["_models.ServerCommunicationLink"]] = None, **kwargs): """ :keyword value: The list of server communication links. :paramtype value: list[~azure.mgmt.sql.models.ServerCommunicationLink] """ - super(ServerCommunicationLinkListResult, self).__init__(**kwargs) + super().__init__(**kwargs) self.value = value @@ -16440,46 +16221,41 @@ class ServerConnectionPolicy(ProxyResource): :vartype location: str :ivar kind: Metadata used for the Azure portal experience. :vartype kind: str - :ivar connection_type: The server connection type. Known values are: "Default", "Redirect", + :ivar connection_type: The server connection type. Known values are: "Default", "Redirect", and "Proxy". :vartype connection_type: str or ~azure.mgmt.sql.models.ServerConnectionType """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'location': {'readonly': True}, - 'kind': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "location": {"readonly": True}, + "kind": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'kind': {'key': 'kind', 'type': 'str'}, - 'connection_type': {'key': 'properties.connectionType', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "kind": {"key": "kind", "type": "str"}, + "connection_type": {"key": "properties.connectionType", "type": "str"}, } - def __init__( - self, - *, - connection_type: Optional[Union[str, "_models.ServerConnectionType"]] = None, - **kwargs - ): + def __init__(self, *, connection_type: Optional[Union[str, "_models.ServerConnectionType"]] = None, **kwargs): """ :keyword connection_type: The server connection type. Known values are: "Default", "Redirect", - "Proxy". + and "Proxy". :paramtype connection_type: str or ~azure.mgmt.sql.models.ServerConnectionType """ - super(ServerConnectionPolicy, self).__init__(**kwargs) + super().__init__(**kwargs) self.location = None self.kind = None self.connection_type = connection_type -class ServerConnectionPolicyListResult(msrest.serialization.Model): +class ServerConnectionPolicyListResult(_serialization.Model): """A list of server connection policy objects. Variables are only populated by the server, and will be ignored when sending a request. @@ -16491,22 +16267,18 @@ class ServerConnectionPolicyListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ServerConnectionPolicy]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ServerConnectionPolicy]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ServerConnectionPolicyListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -16528,20 +16300,20 @@ class ServerDevOpsAuditingSettings(ProxyResource): Monitor. In order to send the events to Azure Monitor, specify 'State' as 'Enabled' and 'IsAzureMonitorTargetEnabled' as true. - + When using REST API to configure DevOps audit, Diagnostic Settings with 'DevOpsOperationsAudit' diagnostic logs category on the master database should be also created. - + Diagnostic Settings URI format: PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/master/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview - + For more information, see `Diagnostic Settings REST API `_ or `Diagnostic Settings PowerShell `_. :vartype is_azure_monitor_target_enabled: bool :ivar state: Specifies the state of the audit. If state is Enabled, storageEndpoint or - isAzureMonitorTargetEnabled are required. Known values are: "Enabled", "Disabled". + isAzureMonitorTargetEnabled are required. Known values are: "Enabled" and "Disabled". :vartype state: str or ~azure.mgmt.sql.models.BlobAuditingPolicyState :ivar storage_endpoint: Specifies the blob storage endpoint (e.g. https://MyAccount.blob.core.windows.net). If state is Enabled, storageEndpoint or @@ -16552,8 +16324,8 @@ class ServerDevOpsAuditingSettings(ProxyResource): storageAccountAccessKey will use SQL server system-assigned managed identity to access the storage. Prerequisites for using managed identity authentication: - - + + #. Assign SQL Server a system-assigned managed identity in Azure Active Directory (AAD). #. Grant SQL Server identity access to the storage account by adding 'Storage Blob Data Contributor' RBAC role to the server identity. @@ -16565,22 +16337,22 @@ class ServerDevOpsAuditingSettings(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'system_data': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "system_data": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'system_data': {'key': 'systemData', 'type': 'SystemData'}, - 'is_azure_monitor_target_enabled': {'key': 'properties.isAzureMonitorTargetEnabled', 'type': 'bool'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'storage_endpoint': {'key': 'properties.storageEndpoint', 'type': 'str'}, - 'storage_account_access_key': {'key': 'properties.storageAccountAccessKey', 'type': 'str'}, - 'storage_account_subscription_id': {'key': 'properties.storageAccountSubscriptionId', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "system_data": {"key": "systemData", "type": "SystemData"}, + "is_azure_monitor_target_enabled": {"key": "properties.isAzureMonitorTargetEnabled", "type": "bool"}, + "state": {"key": "properties.state", "type": "str"}, + "storage_endpoint": {"key": "properties.storageEndpoint", "type": "str"}, + "storage_account_access_key": {"key": "properties.storageAccountAccessKey", "type": "str"}, + "storage_account_subscription_id": {"key": "properties.storageAccountSubscriptionId", "type": "str"}, } def __init__( @@ -16598,20 +16370,20 @@ def __init__( Azure Monitor. In order to send the events to Azure Monitor, specify 'State' as 'Enabled' and 'IsAzureMonitorTargetEnabled' as true. - + When using REST API to configure DevOps audit, Diagnostic Settings with 'DevOpsOperationsAudit' diagnostic logs category on the master database should be also created. - + Diagnostic Settings URI format: PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/master/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview - + For more information, see `Diagnostic Settings REST API `_ or `Diagnostic Settings PowerShell `_. :paramtype is_azure_monitor_target_enabled: bool :keyword state: Specifies the state of the audit. If state is Enabled, storageEndpoint or - isAzureMonitorTargetEnabled are required. Known values are: "Enabled", "Disabled". + isAzureMonitorTargetEnabled are required. Known values are: "Enabled" and "Disabled". :paramtype state: str or ~azure.mgmt.sql.models.BlobAuditingPolicyState :keyword storage_endpoint: Specifies the blob storage endpoint (e.g. https://MyAccount.blob.core.windows.net). If state is Enabled, storageEndpoint or @@ -16623,8 +16395,8 @@ def __init__( storageAccountAccessKey will use SQL server system-assigned managed identity to access the storage. Prerequisites for using managed identity authentication: - - + + #. Assign SQL Server a system-assigned managed identity in Azure Active Directory (AAD). #. Grant SQL Server identity access to the storage account by adding 'Storage Blob Data Contributor' RBAC role to the server identity. @@ -16634,7 +16406,7 @@ def __init__( :keyword storage_account_subscription_id: Specifies the blob storage subscription Id. :paramtype storage_account_subscription_id: str """ - super(ServerDevOpsAuditingSettings, self).__init__(**kwargs) + super().__init__(**kwargs) self.system_data = None self.is_azure_monitor_target_enabled = is_azure_monitor_target_enabled self.state = state @@ -16643,7 +16415,7 @@ def __init__( self.storage_account_subscription_id = storage_account_subscription_id -class ServerDevOpsAuditSettingsListResult(msrest.serialization.Model): +class ServerDevOpsAuditSettingsListResult(_serialization.Model): """A list of server DevOps audit settings. Variables are only populated by the server, and will be ignored when sending a request. @@ -16655,22 +16427,18 @@ class ServerDevOpsAuditSettingsListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ServerDevOpsAuditingSettings]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ServerDevOpsAuditingSettings]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ServerDevOpsAuditSettingsListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -16691,63 +16459,54 @@ class ServerDnsAlias(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'azure_dns_record': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "azure_dns_record": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'azure_dns_record': {'key': 'properties.azureDnsRecord', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "azure_dns_record": {"key": "properties.azureDnsRecord", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ServerDnsAlias, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.azure_dns_record = None -class ServerDnsAliasAcquisition(msrest.serialization.Model): +class ServerDnsAliasAcquisition(_serialization.Model): """A server dns alias acquisition request. All required parameters must be populated in order to send to Azure. - :ivar old_server_dns_alias_id: Required. The id of the server alias that will be acquired to - point to this server instead. + :ivar old_server_dns_alias_id: The id of the server alias that will be acquired to point to + this server instead. Required. :vartype old_server_dns_alias_id: str """ _validation = { - 'old_server_dns_alias_id': {'required': True}, + "old_server_dns_alias_id": {"required": True}, } _attribute_map = { - 'old_server_dns_alias_id': {'key': 'oldServerDnsAliasId', 'type': 'str'}, + "old_server_dns_alias_id": {"key": "oldServerDnsAliasId", "type": "str"}, } - def __init__( - self, - *, - old_server_dns_alias_id: str, - **kwargs - ): + def __init__(self, *, old_server_dns_alias_id: str, **kwargs): """ - :keyword old_server_dns_alias_id: Required. The id of the server alias that will be acquired to - point to this server instead. + :keyword old_server_dns_alias_id: The id of the server alias that will be acquired to point to + this server instead. Required. :paramtype old_server_dns_alias_id: str """ - super(ServerDnsAliasAcquisition, self).__init__(**kwargs) + super().__init__(**kwargs) self.old_server_dns_alias_id = old_server_dns_alias_id -class ServerDnsAliasListResult(msrest.serialization.Model): +class ServerDnsAliasListResult(_serialization.Model): """A list of server DNS aliases. Variables are only populated by the server, and will be ignored when sending a request. @@ -16759,33 +16518,29 @@ class ServerDnsAliasListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ServerDnsAlias]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ServerDnsAlias]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ServerDnsAliasListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ServerExternalAdministrator(msrest.serialization.Model): +class ServerExternalAdministrator(_serialization.Model): """Properties of a active directory administrator. - :ivar administrator_type: Type of the sever administrator. Known values are: "ActiveDirectory". + :ivar administrator_type: Type of the sever administrator. "ActiveDirectory" :vartype administrator_type: str or ~azure.mgmt.sql.models.AdministratorType :ivar principal_type: Principal Type of the sever administrator. Known values are: "User", - "Group", "Application". + "Group", and "Application". :vartype principal_type: str or ~azure.mgmt.sql.models.PrincipalType :ivar login: Login name of the server administrator. :vartype login: str @@ -16798,12 +16553,12 @@ class ServerExternalAdministrator(msrest.serialization.Model): """ _attribute_map = { - 'administrator_type': {'key': 'administratorType', 'type': 'str'}, - 'principal_type': {'key': 'principalType', 'type': 'str'}, - 'login': {'key': 'login', 'type': 'str'}, - 'sid': {'key': 'sid', 'type': 'str'}, - 'tenant_id': {'key': 'tenantId', 'type': 'str'}, - 'azure_ad_only_authentication': {'key': 'azureADOnlyAuthentication', 'type': 'bool'}, + "administrator_type": {"key": "administratorType", "type": "str"}, + "principal_type": {"key": "principalType", "type": "str"}, + "login": {"key": "login", "type": "str"}, + "sid": {"key": "sid", "type": "str"}, + "tenant_id": {"key": "tenantId", "type": "str"}, + "azure_ad_only_authentication": {"key": "azureADOnlyAuthentication", "type": "bool"}, } def __init__( @@ -16818,11 +16573,10 @@ def __init__( **kwargs ): """ - :keyword administrator_type: Type of the sever administrator. Known values are: - "ActiveDirectory". + :keyword administrator_type: Type of the sever administrator. "ActiveDirectory" :paramtype administrator_type: str or ~azure.mgmt.sql.models.AdministratorType :keyword principal_type: Principal Type of the sever administrator. Known values are: "User", - "Group", "Application". + "Group", and "Application". :paramtype principal_type: str or ~azure.mgmt.sql.models.PrincipalType :keyword login: Login name of the server administrator. :paramtype login: str @@ -16833,7 +16587,7 @@ def __init__( :keyword azure_ad_only_authentication: Azure Active Directory only Authentication enabled. :paramtype azure_ad_only_authentication: bool """ - super(ServerExternalAdministrator, self).__init__(**kwargs) + super().__init__(**kwargs) self.administrator_type = administrator_type self.principal_type = principal_type self.login = login @@ -16842,38 +16596,33 @@ def __init__( self.azure_ad_only_authentication = azure_ad_only_authentication -class ServerInfo(msrest.serialization.Model): +class ServerInfo(_serialization.Model): """Server info for the server trust group. All required parameters must be populated in order to send to Azure. - :ivar server_id: Required. Server Id. + :ivar server_id: Server Id. Required. :vartype server_id: str """ _validation = { - 'server_id': {'required': True}, + "server_id": {"required": True}, } _attribute_map = { - 'server_id': {'key': 'serverId', 'type': 'str'}, + "server_id": {"key": "serverId", "type": "str"}, } - def __init__( - self, - *, - server_id: str, - **kwargs - ): + def __init__(self, *, server_id: str, **kwargs): """ - :keyword server_id: Required. Server Id. + :keyword server_id: Server Id. Required. :paramtype server_id: str """ - super(ServerInfo, self).__init__(**kwargs) + super().__init__(**kwargs) self.server_id = server_id -class ServerKey(ProxyResource): +class ServerKey(ProxyResource): # pylint: disable=too-many-instance-attributes """A server key. Variables are only populated by the server, and will be ignored when sending a request. @@ -16892,7 +16641,7 @@ class ServerKey(ProxyResource): :ivar subregion: Subregion of the server key. :vartype subregion: str :ivar server_key_type: The server key type like 'ServiceManaged', 'AzureKeyVault'. Known values - are: "ServiceManaged", "AzureKeyVault". + are: "ServiceManaged" and "AzureKeyVault". :vartype server_key_type: str or ~azure.mgmt.sql.models.ServerKeyType :ivar uri: The URI of the server key. If the ServerKeyType is AzureKeyVault, then the URI is required. @@ -16906,29 +16655,29 @@ class ServerKey(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'kind': {'readonly': True}, - 'location': {'readonly': True}, - 'subregion': {'readonly': True}, - 'thumbprint': {'readonly': True}, - 'creation_date': {'readonly': True}, - 'auto_rotation_enabled': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "kind": {"readonly": True}, + "location": {"readonly": True}, + "subregion": {"readonly": True}, + "thumbprint": {"readonly": True}, + "creation_date": {"readonly": True}, + "auto_rotation_enabled": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'kind': {'key': 'kind', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'subregion': {'key': 'properties.subregion', 'type': 'str'}, - 'server_key_type': {'key': 'properties.serverKeyType', 'type': 'str'}, - 'uri': {'key': 'properties.uri', 'type': 'str'}, - 'thumbprint': {'key': 'properties.thumbprint', 'type': 'str'}, - 'creation_date': {'key': 'properties.creationDate', 'type': 'iso-8601'}, - 'auto_rotation_enabled': {'key': 'properties.autoRotationEnabled', 'type': 'bool'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "kind": {"key": "kind", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "subregion": {"key": "properties.subregion", "type": "str"}, + "server_key_type": {"key": "properties.serverKeyType", "type": "str"}, + "uri": {"key": "properties.uri", "type": "str"}, + "thumbprint": {"key": "properties.thumbprint", "type": "str"}, + "creation_date": {"key": "properties.creationDate", "type": "iso-8601"}, + "auto_rotation_enabled": {"key": "properties.autoRotationEnabled", "type": "bool"}, } def __init__( @@ -16940,13 +16689,13 @@ def __init__( ): """ :keyword server_key_type: The server key type like 'ServiceManaged', 'AzureKeyVault'. Known - values are: "ServiceManaged", "AzureKeyVault". + values are: "ServiceManaged" and "AzureKeyVault". :paramtype server_key_type: str or ~azure.mgmt.sql.models.ServerKeyType :keyword uri: The URI of the server key. If the ServerKeyType is AzureKeyVault, then the URI is required. :paramtype uri: str """ - super(ServerKey, self).__init__(**kwargs) + super().__init__(**kwargs) self.kind = None self.location = None self.subregion = None @@ -16957,7 +16706,7 @@ def __init__( self.auto_rotation_enabled = None -class ServerKeyListResult(msrest.serialization.Model): +class ServerKeyListResult(_serialization.Model): """A list of server keys. Variables are only populated by the server, and will be ignored when sending a request. @@ -16969,27 +16718,23 @@ class ServerKeyListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ServerKey]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ServerKey]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ServerKeyListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ServerListResult(msrest.serialization.Model): +class ServerListResult(_serialization.Model): """A list of servers. Variables are only populated by the server, and will be ignored when sending a request. @@ -17001,27 +16746,23 @@ class ServerListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[Server]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[Server]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ServerListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ServerOperation(ProxyResource): +class ServerOperation(ProxyResource): # pylint: disable=too-many-instance-attributes """A server operation. Variables are only populated by the server, and will be ignored when sending a request. @@ -17043,7 +16784,7 @@ class ServerOperation(ProxyResource): :ivar start_time: The operation start time. :vartype start_time: ~datetime.datetime :ivar state: The operation state. Known values are: "Pending", "InProgress", "Succeeded", - "Failed", "CancelInProgress", "Cancelled". + "Failed", "CancelInProgress", and "Cancelled". :vartype state: str or ~azure.mgmt.sql.models.ManagementOperationState :ivar error_code: The operation error code. :vartype error_code: int @@ -17062,50 +16803,46 @@ class ServerOperation(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'operation': {'readonly': True}, - 'operation_friendly_name': {'readonly': True}, - 'percent_complete': {'readonly': True}, - 'server_name': {'readonly': True}, - 'start_time': {'readonly': True}, - 'state': {'readonly': True}, - 'error_code': {'readonly': True}, - 'error_description': {'readonly': True}, - 'error_severity': {'readonly': True}, - 'is_user_error': {'readonly': True}, - 'estimated_completion_time': {'readonly': True}, - 'description': {'readonly': True}, - 'is_cancellable': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'operation': {'key': 'properties.operation', 'type': 'str'}, - 'operation_friendly_name': {'key': 'properties.operationFriendlyName', 'type': 'str'}, - 'percent_complete': {'key': 'properties.percentComplete', 'type': 'int'}, - 'server_name': {'key': 'properties.serverName', 'type': 'str'}, - 'start_time': {'key': 'properties.startTime', 'type': 'iso-8601'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'error_code': {'key': 'properties.errorCode', 'type': 'int'}, - 'error_description': {'key': 'properties.errorDescription', 'type': 'str'}, - 'error_severity': {'key': 'properties.errorSeverity', 'type': 'int'}, - 'is_user_error': {'key': 'properties.isUserError', 'type': 'bool'}, - 'estimated_completion_time': {'key': 'properties.estimatedCompletionTime', 'type': 'iso-8601'}, - 'description': {'key': 'properties.description', 'type': 'str'}, - 'is_cancellable': {'key': 'properties.isCancellable', 'type': 'bool'}, - } - - def __init__( - self, - **kwargs - ): - """ - """ - super(ServerOperation, self).__init__(**kwargs) + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "operation": {"readonly": True}, + "operation_friendly_name": {"readonly": True}, + "percent_complete": {"readonly": True}, + "server_name": {"readonly": True}, + "start_time": {"readonly": True}, + "state": {"readonly": True}, + "error_code": {"readonly": True}, + "error_description": {"readonly": True}, + "error_severity": {"readonly": True}, + "is_user_error": {"readonly": True}, + "estimated_completion_time": {"readonly": True}, + "description": {"readonly": True}, + "is_cancellable": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "operation": {"key": "properties.operation", "type": "str"}, + "operation_friendly_name": {"key": "properties.operationFriendlyName", "type": "str"}, + "percent_complete": {"key": "properties.percentComplete", "type": "int"}, + "server_name": {"key": "properties.serverName", "type": "str"}, + "start_time": {"key": "properties.startTime", "type": "iso-8601"}, + "state": {"key": "properties.state", "type": "str"}, + "error_code": {"key": "properties.errorCode", "type": "int"}, + "error_description": {"key": "properties.errorDescription", "type": "str"}, + "error_severity": {"key": "properties.errorSeverity", "type": "int"}, + "is_user_error": {"key": "properties.isUserError", "type": "bool"}, + "estimated_completion_time": {"key": "properties.estimatedCompletionTime", "type": "iso-8601"}, + "description": {"key": "properties.description", "type": "str"}, + "is_cancellable": {"key": "properties.isCancellable", "type": "bool"}, + } + + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.operation = None self.operation_friendly_name = None self.percent_complete = None @@ -17121,7 +16858,7 @@ def __init__( self.is_cancellable = None -class ServerOperationListResult(msrest.serialization.Model): +class ServerOperationListResult(_serialization.Model): """The response to a list server operations request. Variables are only populated by the server, and will be ignored when sending a request. @@ -17133,27 +16870,23 @@ class ServerOperationListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ServerOperation]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ServerOperation]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ServerOperationListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ServerPrivateEndpointConnection(msrest.serialization.Model): +class ServerPrivateEndpointConnection(_serialization.Model): """A private endpoint connection under a server. Variables are only populated by the server, and will be ignored when sending a request. @@ -17165,27 +16898,23 @@ class ServerPrivateEndpointConnection(msrest.serialization.Model): """ _validation = { - 'id': {'readonly': True}, - 'properties': {'readonly': True}, + "id": {"readonly": True}, + "properties": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'properties': {'key': 'properties', 'type': 'PrivateEndpointConnectionProperties'}, + "id": {"key": "id", "type": "str"}, + "properties": {"key": "properties", "type": "PrivateEndpointConnectionProperties"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ServerPrivateEndpointConnection, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.id = None self.properties = None -class ServerSecurityAlertPolicy(ProxyResource): +class ServerSecurityAlertPolicy(ProxyResource): # pylint: disable=too-many-instance-attributes """A server security alert policy. Variables are only populated by the server, and will be ignored when sending a request. @@ -17199,7 +16928,7 @@ class ServerSecurityAlertPolicy(ProxyResource): :ivar system_data: SystemData of SecurityAlertPolicyResource. :vartype system_data: ~azure.mgmt.sql.models.SystemData :ivar state: Specifies the state of the policy, whether it is enabled or disabled or a policy - has not been applied yet on the specific database. Known values are: "Enabled", "Disabled". + has not been applied yet on the specific database. Known values are: "Enabled" and "Disabled". :vartype state: str or ~azure.mgmt.sql.models.SecurityAlertsPolicyState :ivar disabled_alerts: Specifies an array of alerts that are disabled. Allowed values are: Sql_Injection, Sql_Injection_Vulnerability, Access_Anomaly, Data_Exfiltration, Unsafe_Action, @@ -17223,26 +16952,26 @@ class ServerSecurityAlertPolicy(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'system_data': {'readonly': True}, - 'creation_time': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "system_data": {"readonly": True}, + "creation_time": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'system_data': {'key': 'systemData', 'type': 'SystemData'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'disabled_alerts': {'key': 'properties.disabledAlerts', 'type': '[str]'}, - 'email_addresses': {'key': 'properties.emailAddresses', 'type': '[str]'}, - 'email_account_admins': {'key': 'properties.emailAccountAdmins', 'type': 'bool'}, - 'storage_endpoint': {'key': 'properties.storageEndpoint', 'type': 'str'}, - 'storage_account_access_key': {'key': 'properties.storageAccountAccessKey', 'type': 'str'}, - 'retention_days': {'key': 'properties.retentionDays', 'type': 'int'}, - 'creation_time': {'key': 'properties.creationTime', 'type': 'iso-8601'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "system_data": {"key": "systemData", "type": "SystemData"}, + "state": {"key": "properties.state", "type": "str"}, + "disabled_alerts": {"key": "properties.disabledAlerts", "type": "[str]"}, + "email_addresses": {"key": "properties.emailAddresses", "type": "[str]"}, + "email_account_admins": {"key": "properties.emailAccountAdmins", "type": "bool"}, + "storage_endpoint": {"key": "properties.storageEndpoint", "type": "str"}, + "storage_account_access_key": {"key": "properties.storageAccountAccessKey", "type": "str"}, + "retention_days": {"key": "properties.retentionDays", "type": "int"}, + "creation_time": {"key": "properties.creationTime", "type": "iso-8601"}, } def __init__( @@ -17259,7 +16988,7 @@ def __init__( ): """ :keyword state: Specifies the state of the policy, whether it is enabled or disabled or a - policy has not been applied yet on the specific database. Known values are: "Enabled", + policy has not been applied yet on the specific database. Known values are: "Enabled" and "Disabled". :paramtype state: str or ~azure.mgmt.sql.models.SecurityAlertsPolicyState :keyword disabled_alerts: Specifies an array of alerts that are disabled. Allowed values are: @@ -17281,7 +17010,7 @@ def __init__( logs. :paramtype retention_days: int """ - super(ServerSecurityAlertPolicy, self).__init__(**kwargs) + super().__init__(**kwargs) self.system_data = None self.state = state self.disabled_alerts = disabled_alerts @@ -17313,39 +17042,34 @@ class ServerTrustCertificate(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'thumbprint': {'readonly': True}, - 'certificate_name': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "thumbprint": {"readonly": True}, + "certificate_name": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'public_blob': {'key': 'properties.publicBlob', 'type': 'str'}, - 'thumbprint': {'key': 'properties.thumbprint', 'type': 'str'}, - 'certificate_name': {'key': 'properties.certificateName', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "public_blob": {"key": "properties.publicBlob", "type": "str"}, + "thumbprint": {"key": "properties.thumbprint", "type": "str"}, + "certificate_name": {"key": "properties.certificateName", "type": "str"}, } - def __init__( - self, - *, - public_blob: Optional[str] = None, - **kwargs - ): + def __init__(self, *, public_blob: Optional[str] = None, **kwargs): """ :keyword public_blob: The certificate public blob. :paramtype public_blob: str """ - super(ServerTrustCertificate, self).__init__(**kwargs) + super().__init__(**kwargs) self.public_blob = public_blob self.thumbprint = None self.certificate_name = None -class ServerTrustCertificatesListResult(msrest.serialization.Model): +class ServerTrustCertificatesListResult(_serialization.Model): """A list of server trust certificates in instance. Variables are only populated by the server, and will be ignored when sending a request. @@ -17357,22 +17081,18 @@ class ServerTrustCertificatesListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ServerTrustCertificate]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ServerTrustCertificate]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ServerTrustCertificatesListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -17396,17 +17116,17 @@ class ServerTrustGroup(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'group_members': {'key': 'properties.groupMembers', 'type': '[ServerInfo]'}, - 'trust_scopes': {'key': 'properties.trustScopes', 'type': '[str]'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "group_members": {"key": "properties.groupMembers", "type": "[ServerInfo]"}, + "trust_scopes": {"key": "properties.trustScopes", "type": "[str]"}, } def __init__( @@ -17423,12 +17143,12 @@ def __init__( :paramtype trust_scopes: list[str or ~azure.mgmt.sql.models.ServerTrustGroupPropertiesTrustScopesItem] """ - super(ServerTrustGroup, self).__init__(**kwargs) + super().__init__(**kwargs) self.group_members = group_members self.trust_scopes = trust_scopes -class ServerTrustGroupListResult(msrest.serialization.Model): +class ServerTrustGroupListResult(_serialization.Model): """A list of server trust groups. Variables are only populated by the server, and will be ignored when sending a request. @@ -17440,34 +17160,30 @@ class ServerTrustGroupListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ServerTrustGroup]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ServerTrustGroup]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ServerTrustGroupListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class ServerUpdate(msrest.serialization.Model): +class ServerUpdate(_serialization.Model): # pylint: disable=too-many-instance-attributes """An update request for an Azure SQL Database server. Variables are only populated by the server, and will be ignored when sending a request. :ivar identity: Server identity. :vartype identity: ~azure.mgmt.sql.models.ResourceIdentity - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar administrator_login: Administrator username for the server. Once created it cannot be changed. @@ -17488,10 +17204,10 @@ class ServerUpdate(msrest.serialization.Model): :vartype minimal_tls_version: str :ivar public_network_access: Whether or not public endpoint access is allowed for this server. Value is optional but if passed in, must be 'Enabled' or 'Disabled'. Known values are: - "Enabled", "Disabled". + "Enabled" and "Disabled". :vartype public_network_access: str or ~azure.mgmt.sql.models.ServerNetworkAccessFlag :ivar workspace_feature: Whether or not existing server has a workspace created and if it - allows connection from workspace. Known values are: "Connected", "Disconnected". + allows connection from workspace. Known values are: "Connected" and "Disconnected". :vartype workspace_feature: str or ~azure.mgmt.sql.models.ServerWorkspaceFeature :ivar primary_user_assigned_identity_id: The resource id of a user assigned identity to be used by default. @@ -17504,35 +17220,38 @@ class ServerUpdate(msrest.serialization.Model): :vartype administrators: ~azure.mgmt.sql.models.ServerExternalAdministrator :ivar restrict_outbound_network_access: Whether or not to restrict outbound network access for this server. Value is optional but if passed in, must be 'Enabled' or 'Disabled'. Known values - are: "Enabled", "Disabled". + are: "Enabled" and "Disabled". :vartype restrict_outbound_network_access: str or ~azure.mgmt.sql.models.ServerNetworkAccessFlag """ _validation = { - 'state': {'readonly': True}, - 'fully_qualified_domain_name': {'readonly': True}, - 'private_endpoint_connections': {'readonly': True}, - 'workspace_feature': {'readonly': True}, + "state": {"readonly": True}, + "fully_qualified_domain_name": {"readonly": True}, + "private_endpoint_connections": {"readonly": True}, + "workspace_feature": {"readonly": True}, } _attribute_map = { - 'identity': {'key': 'identity', 'type': 'ResourceIdentity'}, - 'tags': {'key': 'tags', 'type': '{str}'}, - 'administrator_login': {'key': 'properties.administratorLogin', 'type': 'str'}, - 'administrator_login_password': {'key': 'properties.administratorLoginPassword', 'type': 'str'}, - 'version': {'key': 'properties.version', 'type': 'str'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'fully_qualified_domain_name': {'key': 'properties.fullyQualifiedDomainName', 'type': 'str'}, - 'private_endpoint_connections': {'key': 'properties.privateEndpointConnections', 'type': '[ServerPrivateEndpointConnection]'}, - 'minimal_tls_version': {'key': 'properties.minimalTlsVersion', 'type': 'str'}, - 'public_network_access': {'key': 'properties.publicNetworkAccess', 'type': 'str'}, - 'workspace_feature': {'key': 'properties.workspaceFeature', 'type': 'str'}, - 'primary_user_assigned_identity_id': {'key': 'properties.primaryUserAssignedIdentityId', 'type': 'str'}, - 'federated_client_id': {'key': 'properties.federatedClientId', 'type': 'str'}, - 'key_id': {'key': 'properties.keyId', 'type': 'str'}, - 'administrators': {'key': 'properties.administrators', 'type': 'ServerExternalAdministrator'}, - 'restrict_outbound_network_access': {'key': 'properties.restrictOutboundNetworkAccess', 'type': 'str'}, + "identity": {"key": "identity", "type": "ResourceIdentity"}, + "tags": {"key": "tags", "type": "{str}"}, + "administrator_login": {"key": "properties.administratorLogin", "type": "str"}, + "administrator_login_password": {"key": "properties.administratorLoginPassword", "type": "str"}, + "version": {"key": "properties.version", "type": "str"}, + "state": {"key": "properties.state", "type": "str"}, + "fully_qualified_domain_name": {"key": "properties.fullyQualifiedDomainName", "type": "str"}, + "private_endpoint_connections": { + "key": "properties.privateEndpointConnections", + "type": "[ServerPrivateEndpointConnection]", + }, + "minimal_tls_version": {"key": "properties.minimalTlsVersion", "type": "str"}, + "public_network_access": {"key": "properties.publicNetworkAccess", "type": "str"}, + "workspace_feature": {"key": "properties.workspaceFeature", "type": "str"}, + "primary_user_assigned_identity_id": {"key": "properties.primaryUserAssignedIdentityId", "type": "str"}, + "federated_client_id": {"key": "properties.federatedClientId", "type": "str"}, + "key_id": {"key": "properties.keyId", "type": "str"}, + "administrators": {"key": "properties.administrators", "type": "ServerExternalAdministrator"}, + "restrict_outbound_network_access": {"key": "properties.restrictOutboundNetworkAccess", "type": "str"}, } def __init__( @@ -17555,7 +17274,7 @@ def __init__( """ :keyword identity: Server identity. :paramtype identity: ~azure.mgmt.sql.models.ResourceIdentity - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] :keyword administrator_login: Administrator username for the server. Once created it cannot be changed. @@ -17569,7 +17288,7 @@ def __init__( :paramtype minimal_tls_version: str :keyword public_network_access: Whether or not public endpoint access is allowed for this server. Value is optional but if passed in, must be 'Enabled' or 'Disabled'. Known values are: - "Enabled", "Disabled". + "Enabled" and "Disabled". :paramtype public_network_access: str or ~azure.mgmt.sql.models.ServerNetworkAccessFlag :keyword primary_user_assigned_identity_id: The resource id of a user assigned identity to be used by default. @@ -17582,11 +17301,11 @@ def __init__( :paramtype administrators: ~azure.mgmt.sql.models.ServerExternalAdministrator :keyword restrict_outbound_network_access: Whether or not to restrict outbound network access for this server. Value is optional but if passed in, must be 'Enabled' or 'Disabled'. Known - values are: "Enabled", "Disabled". + values are: "Enabled" and "Disabled". :paramtype restrict_outbound_network_access: str or ~azure.mgmt.sql.models.ServerNetworkAccessFlag """ - super(ServerUpdate, self).__init__(**kwargs) + super().__init__(**kwargs) self.identity = identity self.tags = tags self.administrator_login = administrator_login @@ -17605,7 +17324,7 @@ def __init__( self.restrict_outbound_network_access = restrict_outbound_network_access -class ServerUsage(msrest.serialization.Model): +class ServerUsage(_serialization.Model): """Represents server metrics. Variables are only populated by the server, and will be ignored when sending a request. @@ -17627,32 +17346,28 @@ class ServerUsage(msrest.serialization.Model): """ _validation = { - 'name': {'readonly': True}, - 'resource_name': {'readonly': True}, - 'display_name': {'readonly': True}, - 'current_value': {'readonly': True}, - 'limit': {'readonly': True}, - 'unit': {'readonly': True}, - 'next_reset_time': {'readonly': True}, + "name": {"readonly": True}, + "resource_name": {"readonly": True}, + "display_name": {"readonly": True}, + "current_value": {"readonly": True}, + "limit": {"readonly": True}, + "unit": {"readonly": True}, + "next_reset_time": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'resource_name': {'key': 'resourceName', 'type': 'str'}, - 'display_name': {'key': 'displayName', 'type': 'str'}, - 'current_value': {'key': 'currentValue', 'type': 'float'}, - 'limit': {'key': 'limit', 'type': 'float'}, - 'unit': {'key': 'unit', 'type': 'str'}, - 'next_reset_time': {'key': 'nextResetTime', 'type': 'iso-8601'}, - } - - def __init__( - self, - **kwargs - ): - """ - """ - super(ServerUsage, self).__init__(**kwargs) + "name": {"key": "name", "type": "str"}, + "resource_name": {"key": "resourceName", "type": "str"}, + "display_name": {"key": "displayName", "type": "str"}, + "current_value": {"key": "currentValue", "type": "float"}, + "limit": {"key": "limit", "type": "float"}, + "unit": {"key": "unit", "type": "str"}, + "next_reset_time": {"key": "nextResetTime", "type": "iso-8601"}, + } + + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.name = None self.resource_name = None self.display_name = None @@ -17662,38 +17377,33 @@ def __init__( self.next_reset_time = None -class ServerUsageListResult(msrest.serialization.Model): +class ServerUsageListResult(_serialization.Model): """Represents the response to a list server metrics request. All required parameters must be populated in order to send to Azure. - :ivar value: Required. The list of server metrics for the server. + :ivar value: The list of server metrics for the server. Required. :vartype value: list[~azure.mgmt.sql.models.ServerUsage] """ _validation = { - 'value': {'required': True}, + "value": {"required": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ServerUsage]'}, + "value": {"key": "value", "type": "[ServerUsage]"}, } - def __init__( - self, - *, - value: List["_models.ServerUsage"], - **kwargs - ): + def __init__(self, *, value: List["_models.ServerUsage"], **kwargs): """ - :keyword value: Required. The list of server metrics for the server. + :keyword value: The list of server metrics for the server. Required. :paramtype value: list[~azure.mgmt.sql.models.ServerUsage] """ - super(ServerUsageListResult, self).__init__(**kwargs) + super().__init__(**kwargs) self.value = value -class ServerVersionCapability(msrest.serialization.Model): +class ServerVersionCapability(_serialization.Model): """The server capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -17706,38 +17416,36 @@ class ServerVersionCapability(msrest.serialization.Model): :vartype supported_elastic_pool_editions: list[~azure.mgmt.sql.models.ElasticPoolEditionCapability] :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'name': {'readonly': True}, - 'supported_editions': {'readonly': True}, - 'supported_elastic_pool_editions': {'readonly': True}, - 'status': {'readonly': True}, + "name": {"readonly": True}, + "supported_editions": {"readonly": True}, + "supported_elastic_pool_editions": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'supported_editions': {'key': 'supportedEditions', 'type': '[EditionCapability]'}, - 'supported_elastic_pool_editions': {'key': 'supportedElasticPoolEditions', 'type': '[ElasticPoolEditionCapability]'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "name": {"key": "name", "type": "str"}, + "supported_editions": {"key": "supportedEditions", "type": "[EditionCapability]"}, + "supported_elastic_pool_editions": { + "key": "supportedElasticPoolEditions", + "type": "[ElasticPoolEditionCapability]", + }, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(ServerVersionCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.name = None self.supported_editions = None self.supported_elastic_pool_editions = None @@ -17775,19 +17483,22 @@ class ServerVulnerabilityAssessment(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'storage_container_path': {'key': 'properties.storageContainerPath', 'type': 'str'}, - 'storage_container_sas_key': {'key': 'properties.storageContainerSasKey', 'type': 'str'}, - 'storage_account_access_key': {'key': 'properties.storageAccountAccessKey', 'type': 'str'}, - 'recurring_scans': {'key': 'properties.recurringScans', 'type': 'VulnerabilityAssessmentRecurringScansProperties'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "storage_container_path": {"key": "properties.storageContainerPath", "type": "str"}, + "storage_container_sas_key": {"key": "properties.storageContainerSasKey", "type": "str"}, + "storage_account_access_key": {"key": "properties.storageAccountAccessKey", "type": "str"}, + "recurring_scans": { + "key": "properties.recurringScans", + "type": "VulnerabilityAssessmentRecurringScansProperties", + }, } def __init__( @@ -17817,14 +17528,14 @@ def __init__( :paramtype recurring_scans: ~azure.mgmt.sql.models.VulnerabilityAssessmentRecurringScansProperties """ - super(ServerVulnerabilityAssessment, self).__init__(**kwargs) + super().__init__(**kwargs) self.storage_container_path = storage_container_path self.storage_container_sas_key = storage_container_sas_key self.storage_account_access_key = storage_account_access_key self.recurring_scans = recurring_scans -class ServerVulnerabilityAssessmentListResult(msrest.serialization.Model): +class ServerVulnerabilityAssessmentListResult(_serialization.Model): """A list of the server's vulnerability assessments. Variables are only populated by the server, and will be ignored when sending a request. @@ -17836,22 +17547,18 @@ class ServerVulnerabilityAssessmentListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ServerVulnerabilityAssessment]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[ServerVulnerabilityAssessment]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ServerVulnerabilityAssessmentListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -17880,34 +17587,30 @@ class ServiceObjective(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'service_objective_name': {'readonly': True}, - 'is_default': {'readonly': True}, - 'is_system': {'readonly': True}, - 'description': {'readonly': True}, - 'enabled': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "service_objective_name": {"readonly": True}, + "is_default": {"readonly": True}, + "is_system": {"readonly": True}, + "description": {"readonly": True}, + "enabled": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'service_objective_name': {'key': 'properties.serviceObjectiveName', 'type': 'str'}, - 'is_default': {'key': 'properties.isDefault', 'type': 'bool'}, - 'is_system': {'key': 'properties.isSystem', 'type': 'bool'}, - 'description': {'key': 'properties.description', 'type': 'str'}, - 'enabled': {'key': 'properties.enabled', 'type': 'bool'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "service_objective_name": {"key": "properties.serviceObjectiveName", "type": "str"}, + "is_default": {"key": "properties.isDefault", "type": "bool"}, + "is_system": {"key": "properties.isSystem", "type": "bool"}, + "description": {"key": "properties.description", "type": "str"}, + "enabled": {"key": "properties.enabled", "type": "bool"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(ServiceObjective, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.service_objective_name = None self.is_default = None self.is_system = None @@ -17915,7 +17618,7 @@ def __init__( self.enabled = None -class ServiceObjectiveCapability(msrest.serialization.Model): +class ServiceObjectiveCapability(_serialization.Model): # pylint: disable=too-many-instance-attributes """The service objectives capability. Variables are only populated by the server, and will be ignored when sending a request. @@ -17946,56 +17649,54 @@ class ServiceObjectiveCapability(msrest.serialization.Model): :vartype supported_maintenance_configurations: list[~azure.mgmt.sql.models.MaintenanceConfigurationCapability] :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'supported_max_sizes': {'readonly': True}, - 'performance_level': {'readonly': True}, - 'sku': {'readonly': True}, - 'supported_license_types': {'readonly': True}, - 'included_max_size': {'readonly': True}, - 'zone_redundant': {'readonly': True}, - 'supported_auto_pause_delay': {'readonly': True}, - 'supported_min_capacities': {'readonly': True}, - 'compute_model': {'readonly': True}, - 'supported_maintenance_configurations': {'readonly': True}, - 'status': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'supported_max_sizes': {'key': 'supportedMaxSizes', 'type': '[MaxSizeRangeCapability]'}, - 'performance_level': {'key': 'performanceLevel', 'type': 'PerformanceLevelCapability'}, - 'sku': {'key': 'sku', 'type': 'Sku'}, - 'supported_license_types': {'key': 'supportedLicenseTypes', 'type': '[LicenseTypeCapability]'}, - 'included_max_size': {'key': 'includedMaxSize', 'type': 'MaxSizeCapability'}, - 'zone_redundant': {'key': 'zoneRedundant', 'type': 'bool'}, - 'supported_auto_pause_delay': {'key': 'supportedAutoPauseDelay', 'type': 'AutoPauseDelayTimeRange'}, - 'supported_min_capacities': {'key': 'supportedMinCapacities', 'type': '[MinCapacityCapability]'}, - 'compute_model': {'key': 'computeModel', 'type': 'str'}, - 'supported_maintenance_configurations': {'key': 'supportedMaintenanceConfigurations', 'type': '[MaintenanceConfigurationCapability]'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, - } - - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + "id": {"readonly": True}, + "name": {"readonly": True}, + "supported_max_sizes": {"readonly": True}, + "performance_level": {"readonly": True}, + "sku": {"readonly": True}, + "supported_license_types": {"readonly": True}, + "included_max_size": {"readonly": True}, + "zone_redundant": {"readonly": True}, + "supported_auto_pause_delay": {"readonly": True}, + "supported_min_capacities": {"readonly": True}, + "compute_model": {"readonly": True}, + "supported_maintenance_configurations": {"readonly": True}, + "status": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "supported_max_sizes": {"key": "supportedMaxSizes", "type": "[MaxSizeRangeCapability]"}, + "performance_level": {"key": "performanceLevel", "type": "PerformanceLevelCapability"}, + "sku": {"key": "sku", "type": "Sku"}, + "supported_license_types": {"key": "supportedLicenseTypes", "type": "[LicenseTypeCapability]"}, + "included_max_size": {"key": "includedMaxSize", "type": "MaxSizeCapability"}, + "zone_redundant": {"key": "zoneRedundant", "type": "bool"}, + "supported_auto_pause_delay": {"key": "supportedAutoPauseDelay", "type": "AutoPauseDelayTimeRange"}, + "supported_min_capacities": {"key": "supportedMinCapacities", "type": "[MinCapacityCapability]"}, + "compute_model": {"key": "computeModel", "type": "str"}, + "supported_maintenance_configurations": { + "key": "supportedMaintenanceConfigurations", + "type": "[MaintenanceConfigurationCapability]", + }, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, + } + + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(ServiceObjectiveCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.id = None self.name = None self.supported_max_sizes = None @@ -18012,38 +17713,33 @@ def __init__( self.reason = reason -class ServiceObjectiveListResult(msrest.serialization.Model): +class ServiceObjectiveListResult(_serialization.Model): """Represents the response to a get database service objectives request. All required parameters must be populated in order to send to Azure. - :ivar value: Required. The list of database service objectives. + :ivar value: The list of database service objectives. Required. :vartype value: list[~azure.mgmt.sql.models.ServiceObjective] """ _validation = { - 'value': {'required': True}, + "value": {"required": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[ServiceObjective]'}, + "value": {"key": "value", "type": "[ServiceObjective]"}, } - def __init__( - self, - *, - value: List["_models.ServiceObjective"], - **kwargs - ): + def __init__(self, *, value: List["_models.ServiceObjective"], **kwargs): """ - :keyword value: Required. The list of database service objectives. + :keyword value: The list of database service objectives. Required. :paramtype value: list[~azure.mgmt.sql.models.ServiceObjective] """ - super(ServiceObjectiveListResult, self).__init__(**kwargs) + super().__init__(**kwargs) self.value = value -class ServicePrincipal(msrest.serialization.Model): +class ServicePrincipal(_serialization.Model): """The managed instance's service principal configuration for a resource. Variables are only populated by the server, and will be ignored when sending a request. @@ -18054,46 +17750,41 @@ class ServicePrincipal(msrest.serialization.Model): :vartype client_id: str :ivar tenant_id: The Azure Active Directory tenant id. :vartype tenant_id: str - :ivar type: Service principal type. Known values are: "None", "SystemAssigned". + :ivar type: Service principal type. Known values are: "None" and "SystemAssigned". :vartype type: str or ~azure.mgmt.sql.models.ServicePrincipalType """ _validation = { - 'principal_id': {'readonly': True}, - 'client_id': {'readonly': True}, - 'tenant_id': {'readonly': True}, + "principal_id": {"readonly": True}, + "client_id": {"readonly": True}, + "tenant_id": {"readonly": True}, } _attribute_map = { - 'principal_id': {'key': 'principalId', 'type': 'str'}, - 'client_id': {'key': 'clientId', 'type': 'str'}, - 'tenant_id': {'key': 'tenantId', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, + "principal_id": {"key": "principalId", "type": "str"}, + "client_id": {"key": "clientId", "type": "str"}, + "tenant_id": {"key": "tenantId", "type": "str"}, + "type": {"key": "type", "type": "str"}, } - def __init__( - self, - *, - type: Optional[Union[str, "_models.ServicePrincipalType"]] = None, - **kwargs - ): + def __init__(self, *, type: Optional[Union[str, "_models.ServicePrincipalType"]] = None, **kwargs): """ - :keyword type: Service principal type. Known values are: "None", "SystemAssigned". + :keyword type: Service principal type. Known values are: "None" and "SystemAssigned". :paramtype type: str or ~azure.mgmt.sql.models.ServicePrincipalType """ - super(ServicePrincipal, self).__init__(**kwargs) + super().__init__(**kwargs) self.principal_id = None self.client_id = None self.tenant_id = None self.type = type -class Sku(msrest.serialization.Model): +class Sku(_serialization.Model): """An ARM Resource SKU. All required parameters must be populated in order to send to Azure. - :ivar name: Required. The name of the SKU, typically, a letter + Number code, e.g. P3. + :ivar name: The name of the SKU, typically, a letter + Number code, e.g. P3. Required. :vartype name: str :ivar tier: The tier or edition of the particular SKU, e.g. Basic, Premium. :vartype tier: str @@ -18107,15 +17798,15 @@ class Sku(msrest.serialization.Model): """ _validation = { - 'name': {'required': True}, + "name": {"required": True}, } _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'tier': {'key': 'tier', 'type': 'str'}, - 'size': {'key': 'size', 'type': 'str'}, - 'family': {'key': 'family', 'type': 'str'}, - 'capacity': {'key': 'capacity', 'type': 'int'}, + "name": {"key": "name", "type": "str"}, + "tier": {"key": "tier", "type": "str"}, + "size": {"key": "size", "type": "str"}, + "family": {"key": "family", "type": "str"}, + "capacity": {"key": "capacity", "type": "int"}, } def __init__( @@ -18129,7 +17820,7 @@ def __init__( **kwargs ): """ - :keyword name: Required. The name of the SKU, typically, a letter + Number code, e.g. P3. + :keyword name: The name of the SKU, typically, a letter + Number code, e.g. P3. Required. :paramtype name: str :keyword tier: The tier or edition of the particular SKU, e.g. Basic, Premium. :paramtype tier: str @@ -18141,7 +17832,7 @@ def __init__( :keyword capacity: Capacity of the particular SKU. :paramtype capacity: int """ - super(Sku, self).__init__(**kwargs) + super().__init__(**kwargs) self.name = name self.tier = tier self.size = size @@ -18149,7 +17840,7 @@ def __init__( self.capacity = capacity -class SloUsageMetric(msrest.serialization.Model): +class SloUsageMetric(_serialization.Model): """A Slo Usage Metric. Variables are only populated by the server, and will be ignored when sending a request. @@ -18161,7 +17852,7 @@ class SloUsageMetric(msrest.serialization.Model): "DW400", "DW500", "DW600", "DW1000", "DW1200", "DW1000c", "DW1500", "DW1500c", "DW2000", "DW2000c", "DW3000", "DW2500c", "DW3000c", "DW6000", "DW5000c", "DW6000c", "DW7500c", "DW10000c", "DW15000c", "DW30000c", "DS100", "DS200", "DS300", "DS400", "DS500", "DS600", - "DS1000", "DS1200", "DS1500", "DS2000", "ElasticPool". + "DS1000", "DS1200", "DS1500", "DS2000", and "ElasticPool". :vartype service_level_objective: str or ~azure.mgmt.sql.models.ServiceObjectiveName :ivar service_level_objective_id: The serviceLevelObjectiveId for SLO usage metric. :vartype service_level_objective_id: str @@ -18170,24 +17861,20 @@ class SloUsageMetric(msrest.serialization.Model): """ _validation = { - 'service_level_objective': {'readonly': True}, - 'service_level_objective_id': {'readonly': True}, - 'in_range_time_ratio': {'readonly': True}, + "service_level_objective": {"readonly": True}, + "service_level_objective_id": {"readonly": True}, + "in_range_time_ratio": {"readonly": True}, } _attribute_map = { - 'service_level_objective': {'key': 'serviceLevelObjective', 'type': 'str'}, - 'service_level_objective_id': {'key': 'serviceLevelObjectiveId', 'type': 'str'}, - 'in_range_time_ratio': {'key': 'inRangeTimeRatio', 'type': 'float'}, + "service_level_objective": {"key": "serviceLevelObjective", "type": "str"}, + "service_level_objective_id": {"key": "serviceLevelObjectiveId", "type": "str"}, + "in_range_time_ratio": {"key": "inRangeTimeRatio", "type": "float"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SloUsageMetric, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.service_level_objective = None self.service_level_objective_id = None self.in_range_time_ratio = None @@ -18204,75 +17891,65 @@ class SqlAgentConfiguration(ProxyResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar state: The state of Sql Agent. Known values are: "Enabled", "Disabled". + :ivar state: The state of Sql Agent. Known values are: "Enabled" and "Disabled". :vartype state: str or ~azure.mgmt.sql.models.SqlAgentConfigurationPropertiesState """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'state': {'key': 'properties.state', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "state": {"key": "properties.state", "type": "str"}, } - def __init__( - self, - *, - state: Optional[Union[str, "_models.SqlAgentConfigurationPropertiesState"]] = None, - **kwargs - ): + def __init__(self, *, state: Optional[Union[str, "_models.SqlAgentConfigurationPropertiesState"]] = None, **kwargs): """ - :keyword state: The state of Sql Agent. Known values are: "Enabled", "Disabled". + :keyword state: The state of Sql Agent. Known values are: "Enabled" and "Disabled". :paramtype state: str or ~azure.mgmt.sql.models.SqlAgentConfigurationPropertiesState """ - super(SqlAgentConfiguration, self).__init__(**kwargs) + super().__init__(**kwargs) self.state = state -class StorageCapability(msrest.serialization.Model): +class StorageCapability(_serialization.Model): """The storage account type capability. Variables are only populated by the server, and will be ignored when sending a request. :ivar storage_account_type: The storage account type for the database's backups. Known values - are: "GRS", "LRS", "ZRS". + are: "GRS", "LRS", and "ZRS". :vartype storage_account_type: str or ~azure.mgmt.sql.models.StorageCapabilityStorageAccountType :ivar status: The status of the capability. Known values are: "Visible", "Available", - "Default", "Disabled". + "Default", and "Disabled". :vartype status: str or ~azure.mgmt.sql.models.CapabilityStatus :ivar reason: The reason for the capability not being available. :vartype reason: str """ _validation = { - 'storage_account_type': {'readonly': True}, - 'status': {'readonly': True}, + "storage_account_type": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'storage_account_type': {'key': 'storageAccountType', 'type': 'str'}, - 'status': {'key': 'status', 'type': 'str'}, - 'reason': {'key': 'reason', 'type': 'str'}, + "storage_account_type": {"key": "storageAccountType", "type": "str"}, + "status": {"key": "status", "type": "str"}, + "reason": {"key": "reason", "type": "str"}, } - def __init__( - self, - *, - reason: Optional[str] = None, - **kwargs - ): + def __init__(self, *, reason: Optional[str] = None, **kwargs): """ :keyword reason: The reason for the capability not being available. :paramtype reason: str """ - super(StorageCapability, self).__init__(**kwargs) + super().__init__(**kwargs) self.storage_account_type = None self.status = None self.reason = reason @@ -18300,39 +17977,35 @@ class SubscriptionUsage(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'display_name': {'readonly': True}, - 'current_value': {'readonly': True}, - 'limit': {'readonly': True}, - 'unit': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "display_name": {"readonly": True}, + "current_value": {"readonly": True}, + "limit": {"readonly": True}, + "unit": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'display_name': {'key': 'properties.displayName', 'type': 'str'}, - 'current_value': {'key': 'properties.currentValue', 'type': 'float'}, - 'limit': {'key': 'properties.limit', 'type': 'float'}, - 'unit': {'key': 'properties.unit', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "display_name": {"key": "properties.displayName", "type": "str"}, + "current_value": {"key": "properties.currentValue", "type": "float"}, + "limit": {"key": "properties.limit", "type": "float"}, + "unit": {"key": "properties.unit", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SubscriptionUsage, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.display_name = None self.current_value = None self.limit = None self.unit = None -class SubscriptionUsageListResult(msrest.serialization.Model): +class SubscriptionUsageListResult(_serialization.Model): """A list of subscription usage metrics in a location. Variables are only populated by the server, and will be ignored when sending a request. @@ -18344,22 +18017,18 @@ class SubscriptionUsageListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[SubscriptionUsage]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[SubscriptionUsage]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SubscriptionUsageListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -18381,7 +18050,8 @@ class SyncAgent(ProxyResource): :vartype sync_database_id: str :ivar last_alive_time: Last alive time of the sync agent. :vartype last_alive_time: ~datetime.datetime - :ivar state: State of the sync agent. Known values are: "Online", "Offline", "NeverConnected". + :ivar state: State of the sync agent. Known values are: "Online", "Offline", and + "NeverConnected". :vartype state: str or ~azure.mgmt.sql.models.SyncAgentState :ivar is_up_to_date: If the sync agent version is up to date. :vartype is_up_to_date: bool @@ -18392,41 +18062,36 @@ class SyncAgent(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'name_properties_name': {'readonly': True}, - 'last_alive_time': {'readonly': True}, - 'state': {'readonly': True}, - 'is_up_to_date': {'readonly': True}, - 'expiry_time': {'readonly': True}, - 'version': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "name_properties_name": {"readonly": True}, + "last_alive_time": {"readonly": True}, + "state": {"readonly": True}, + "is_up_to_date": {"readonly": True}, + "expiry_time": {"readonly": True}, + "version": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'name_properties_name': {'key': 'properties.name', 'type': 'str'}, - 'sync_database_id': {'key': 'properties.syncDatabaseId', 'type': 'str'}, - 'last_alive_time': {'key': 'properties.lastAliveTime', 'type': 'iso-8601'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'is_up_to_date': {'key': 'properties.isUpToDate', 'type': 'bool'}, - 'expiry_time': {'key': 'properties.expiryTime', 'type': 'iso-8601'}, - 'version': {'key': 'properties.version', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "name_properties_name": {"key": "properties.name", "type": "str"}, + "sync_database_id": {"key": "properties.syncDatabaseId", "type": "str"}, + "last_alive_time": {"key": "properties.lastAliveTime", "type": "iso-8601"}, + "state": {"key": "properties.state", "type": "str"}, + "is_up_to_date": {"key": "properties.isUpToDate", "type": "bool"}, + "expiry_time": {"key": "properties.expiryTime", "type": "iso-8601"}, + "version": {"key": "properties.version", "type": "str"}, } - def __init__( - self, - *, - sync_database_id: Optional[str] = None, - **kwargs - ): + def __init__(self, *, sync_database_id: Optional[str] = None, **kwargs): """ :keyword sync_database_id: ARM resource id of the sync database in the sync agent. :paramtype sync_database_id: str """ - super(SyncAgent, self).__init__(**kwargs) + super().__init__(**kwargs) self.name_properties_name = None self.sync_database_id = sync_database_id self.last_alive_time = None @@ -18436,7 +18101,7 @@ def __init__( self.version = None -class SyncAgentKeyProperties(msrest.serialization.Model): +class SyncAgentKeyProperties(_serialization.Model): """Properties of an Azure SQL Database sync agent key. Variables are only populated by the server, and will be ignored when sending a request. @@ -18446,20 +18111,16 @@ class SyncAgentKeyProperties(msrest.serialization.Model): """ _validation = { - 'sync_agent_key': {'readonly': True}, + "sync_agent_key": {"readonly": True}, } _attribute_map = { - 'sync_agent_key': {'key': 'syncAgentKey', 'type': 'str'}, + "sync_agent_key": {"key": "syncAgentKey", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SyncAgentKeyProperties, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.sync_agent_key = None @@ -18475,7 +18136,7 @@ class SyncAgentLinkedDatabase(ProxyResource): :ivar type: Resource type. :vartype type: str :ivar database_type: Type of the sync agent linked database. Known values are: - "AzureSqlDatabase", "SqlServerDatabase". + "AzureSqlDatabase" and "SqlServerDatabase". :vartype database_type: str or ~azure.mgmt.sql.models.SyncMemberDbType :ivar database_id: Id of the sync agent linked database. :vartype database_id: str @@ -18490,36 +18151,32 @@ class SyncAgentLinkedDatabase(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'database_type': {'readonly': True}, - 'database_id': {'readonly': True}, - 'description': {'readonly': True}, - 'server_name': {'readonly': True}, - 'database_name': {'readonly': True}, - 'user_name': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "database_type": {"readonly": True}, + "database_id": {"readonly": True}, + "description": {"readonly": True}, + "server_name": {"readonly": True}, + "database_name": {"readonly": True}, + "user_name": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'database_type': {'key': 'properties.databaseType', 'type': 'str'}, - 'database_id': {'key': 'properties.databaseId', 'type': 'str'}, - 'description': {'key': 'properties.description', 'type': 'str'}, - 'server_name': {'key': 'properties.serverName', 'type': 'str'}, - 'database_name': {'key': 'properties.databaseName', 'type': 'str'}, - 'user_name': {'key': 'properties.userName', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "database_type": {"key": "properties.databaseType", "type": "str"}, + "database_id": {"key": "properties.databaseId", "type": "str"}, + "description": {"key": "properties.description", "type": "str"}, + "server_name": {"key": "properties.serverName", "type": "str"}, + "database_name": {"key": "properties.databaseName", "type": "str"}, + "user_name": {"key": "properties.userName", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SyncAgentLinkedDatabase, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.database_type = None self.database_id = None self.description = None @@ -18528,7 +18185,7 @@ def __init__( self.user_name = None -class SyncAgentLinkedDatabaseListResult(msrest.serialization.Model): +class SyncAgentLinkedDatabaseListResult(_serialization.Model): """A list of sync agent linked databases. Variables are only populated by the server, and will be ignored when sending a request. @@ -18540,27 +18197,23 @@ class SyncAgentLinkedDatabaseListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[SyncAgentLinkedDatabase]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[SyncAgentLinkedDatabase]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SyncAgentLinkedDatabaseListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class SyncAgentListResult(msrest.serialization.Model): +class SyncAgentListResult(_serialization.Model): """A list of sync agents. Variables are only populated by the server, and will be ignored when sending a request. @@ -18572,27 +18225,23 @@ class SyncAgentListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[SyncAgent]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[SyncAgent]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SyncAgentListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class SyncDatabaseIdListResult(msrest.serialization.Model): +class SyncDatabaseIdListResult(_serialization.Model): """A list of sync database ID properties. Variables are only populated by the server, and will be ignored when sending a request. @@ -18604,27 +18253,23 @@ class SyncDatabaseIdListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[SyncDatabaseIdProperties]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[SyncDatabaseIdProperties]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SyncDatabaseIdListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class SyncDatabaseIdProperties(msrest.serialization.Model): +class SyncDatabaseIdProperties(_serialization.Model): """Properties of the sync database id. Variables are only populated by the server, and will be ignored when sending a request. @@ -18634,24 +18279,20 @@ class SyncDatabaseIdProperties(msrest.serialization.Model): """ _validation = { - 'id': {'readonly': True}, + "id": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SyncDatabaseIdProperties, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.id = None -class SyncFullSchemaProperties(msrest.serialization.Model): +class SyncFullSchemaProperties(_serialization.Model): """Properties of the database full schema. Variables are only populated by the server, and will be ignored when sending a request. @@ -18663,27 +18304,23 @@ class SyncFullSchemaProperties(msrest.serialization.Model): """ _validation = { - 'tables': {'readonly': True}, - 'last_update_time': {'readonly': True}, + "tables": {"readonly": True}, + "last_update_time": {"readonly": True}, } _attribute_map = { - 'tables': {'key': 'tables', 'type': '[SyncFullSchemaTable]'}, - 'last_update_time': {'key': 'lastUpdateTime', 'type': 'iso-8601'}, + "tables": {"key": "tables", "type": "[SyncFullSchemaTable]"}, + "last_update_time": {"key": "lastUpdateTime", "type": "iso-8601"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SyncFullSchemaProperties, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.tables = None self.last_update_time = None -class SyncFullSchemaPropertiesListResult(msrest.serialization.Model): +class SyncFullSchemaPropertiesListResult(_serialization.Model): """A list of sync schema properties. Variables are only populated by the server, and will be ignored when sending a request. @@ -18695,27 +18332,23 @@ class SyncFullSchemaPropertiesListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[SyncFullSchemaProperties]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[SyncFullSchemaProperties]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SyncFullSchemaPropertiesListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class SyncFullSchemaTable(msrest.serialization.Model): +class SyncFullSchemaTable(_serialization.Model): """Properties of the table in the database full schema. Variables are only populated by the server, and will be ignored when sending a request. @@ -18733,28 +18366,24 @@ class SyncFullSchemaTable(msrest.serialization.Model): """ _validation = { - 'columns': {'readonly': True}, - 'error_id': {'readonly': True}, - 'has_error': {'readonly': True}, - 'name': {'readonly': True}, - 'quoted_name': {'readonly': True}, + "columns": {"readonly": True}, + "error_id": {"readonly": True}, + "has_error": {"readonly": True}, + "name": {"readonly": True}, + "quoted_name": {"readonly": True}, } _attribute_map = { - 'columns': {'key': 'columns', 'type': '[SyncFullSchemaTableColumn]'}, - 'error_id': {'key': 'errorId', 'type': 'str'}, - 'has_error': {'key': 'hasError', 'type': 'bool'}, - 'name': {'key': 'name', 'type': 'str'}, - 'quoted_name': {'key': 'quotedName', 'type': 'str'}, + "columns": {"key": "columns", "type": "[SyncFullSchemaTableColumn]"}, + "error_id": {"key": "errorId", "type": "str"}, + "has_error": {"key": "hasError", "type": "bool"}, + "name": {"key": "name", "type": "str"}, + "quoted_name": {"key": "quotedName", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SyncFullSchemaTable, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.columns = None self.error_id = None self.has_error = None @@ -18762,7 +18391,7 @@ def __init__( self.quoted_name = None -class SyncFullSchemaTableColumn(msrest.serialization.Model): +class SyncFullSchemaTableColumn(_serialization.Model): """Properties of the column in the table of database full schema. Variables are only populated by the server, and will be ignored when sending a request. @@ -18784,32 +18413,28 @@ class SyncFullSchemaTableColumn(msrest.serialization.Model): """ _validation = { - 'data_size': {'readonly': True}, - 'data_type': {'readonly': True}, - 'error_id': {'readonly': True}, - 'has_error': {'readonly': True}, - 'is_primary_key': {'readonly': True}, - 'name': {'readonly': True}, - 'quoted_name': {'readonly': True}, + "data_size": {"readonly": True}, + "data_type": {"readonly": True}, + "error_id": {"readonly": True}, + "has_error": {"readonly": True}, + "is_primary_key": {"readonly": True}, + "name": {"readonly": True}, + "quoted_name": {"readonly": True}, } _attribute_map = { - 'data_size': {'key': 'dataSize', 'type': 'str'}, - 'data_type': {'key': 'dataType', 'type': 'str'}, - 'error_id': {'key': 'errorId', 'type': 'str'}, - 'has_error': {'key': 'hasError', 'type': 'bool'}, - 'is_primary_key': {'key': 'isPrimaryKey', 'type': 'bool'}, - 'name': {'key': 'name', 'type': 'str'}, - 'quoted_name': {'key': 'quotedName', 'type': 'str'}, + "data_size": {"key": "dataSize", "type": "str"}, + "data_type": {"key": "dataType", "type": "str"}, + "error_id": {"key": "errorId", "type": "str"}, + "has_error": {"key": "hasError", "type": "bool"}, + "is_primary_key": {"key": "isPrimaryKey", "type": "bool"}, + "name": {"key": "name", "type": "str"}, + "quoted_name": {"key": "quotedName", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SyncFullSchemaTableColumn, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.data_size = None self.data_type = None self.error_id = None @@ -18819,7 +18444,7 @@ def __init__( self.quoted_name = None -class SyncGroup(ProxyResource): +class SyncGroup(ProxyResource): # pylint: disable=too-many-instance-attributes """An Azure SQL Database sync group. Variables are only populated by the server, and will be ignored when sending a request. @@ -18837,7 +18462,7 @@ class SyncGroup(ProxyResource): :ivar last_sync_time: Last sync time of the sync group. :vartype last_sync_time: ~datetime.datetime :ivar conflict_resolution_policy: Conflict resolution policy of the sync group. Known values - are: "HubWin", "MemberWin". + are: "HubWin" and "MemberWin". :vartype conflict_resolution_policy: str or ~azure.mgmt.sql.models.SyncConflictResolutionPolicy :ivar sync_database_id: ARM resource id of the sync database in the sync group. :vartype sync_database_id: str @@ -18846,7 +18471,7 @@ class SyncGroup(ProxyResource): :ivar hub_database_password: Password for the sync group hub database credential. :vartype hub_database_password: str :ivar sync_state: Sync state of the sync group. Known values are: "NotReady", "Error", - "Warning", "Progressing", "Good". + "Warning", "Progressing", and "Good". :vartype sync_state: str or ~azure.mgmt.sql.models.SyncGroupState :ivar schema: Sync schema of the sync group. :vartype schema: ~azure.mgmt.sql.models.SyncGroupSchema @@ -18862,31 +18487,31 @@ class SyncGroup(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'last_sync_time': {'readonly': True}, - 'sync_state': {'readonly': True}, - 'private_endpoint_name': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "last_sync_time": {"readonly": True}, + "sync_state": {"readonly": True}, + "private_endpoint_name": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'sku': {'key': 'sku', 'type': 'Sku'}, - 'interval': {'key': 'properties.interval', 'type': 'int'}, - 'last_sync_time': {'key': 'properties.lastSyncTime', 'type': 'iso-8601'}, - 'conflict_resolution_policy': {'key': 'properties.conflictResolutionPolicy', 'type': 'str'}, - 'sync_database_id': {'key': 'properties.syncDatabaseId', 'type': 'str'}, - 'hub_database_user_name': {'key': 'properties.hubDatabaseUserName', 'type': 'str'}, - 'hub_database_password': {'key': 'properties.hubDatabasePassword', 'type': 'str'}, - 'sync_state': {'key': 'properties.syncState', 'type': 'str'}, - 'schema': {'key': 'properties.schema', 'type': 'SyncGroupSchema'}, - 'enable_conflict_logging': {'key': 'properties.enableConflictLogging', 'type': 'bool'}, - 'conflict_logging_retention_in_days': {'key': 'properties.conflictLoggingRetentionInDays', 'type': 'int'}, - 'use_private_link_connection': {'key': 'properties.usePrivateLinkConnection', 'type': 'bool'}, - 'private_endpoint_name': {'key': 'properties.privateEndpointName', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "sku": {"key": "sku", "type": "Sku"}, + "interval": {"key": "properties.interval", "type": "int"}, + "last_sync_time": {"key": "properties.lastSyncTime", "type": "iso-8601"}, + "conflict_resolution_policy": {"key": "properties.conflictResolutionPolicy", "type": "str"}, + "sync_database_id": {"key": "properties.syncDatabaseId", "type": "str"}, + "hub_database_user_name": {"key": "properties.hubDatabaseUserName", "type": "str"}, + "hub_database_password": {"key": "properties.hubDatabasePassword", "type": "str"}, + "sync_state": {"key": "properties.syncState", "type": "str"}, + "schema": {"key": "properties.schema", "type": "SyncGroupSchema"}, + "enable_conflict_logging": {"key": "properties.enableConflictLogging", "type": "bool"}, + "conflict_logging_retention_in_days": {"key": "properties.conflictLoggingRetentionInDays", "type": "int"}, + "use_private_link_connection": {"key": "properties.usePrivateLinkConnection", "type": "bool"}, + "private_endpoint_name": {"key": "properties.privateEndpointName", "type": "str"}, } def __init__( @@ -18910,7 +18535,7 @@ def __init__( :keyword interval: Sync interval of the sync group. :paramtype interval: int :keyword conflict_resolution_policy: Conflict resolution policy of the sync group. Known values - are: "HubWin", "MemberWin". + are: "HubWin" and "MemberWin". :paramtype conflict_resolution_policy: str or ~azure.mgmt.sql.models.SyncConflictResolutionPolicy :keyword sync_database_id: ARM resource id of the sync database in the sync group. @@ -18928,7 +18553,7 @@ def __init__( :keyword use_private_link_connection: If use private link connection is enabled. :paramtype use_private_link_connection: bool """ - super(SyncGroup, self).__init__(**kwargs) + super().__init__(**kwargs) self.sku = sku self.interval = interval self.last_sync_time = None @@ -18944,7 +18569,7 @@ def __init__( self.private_endpoint_name = None -class SyncGroupListResult(msrest.serialization.Model): +class SyncGroupListResult(_serialization.Model): """A list of sync groups. Variables are only populated by the server, and will be ignored when sending a request. @@ -18956,27 +18581,23 @@ class SyncGroupListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[SyncGroup]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[SyncGroup]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SyncGroupListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class SyncGroupLogListResult(msrest.serialization.Model): +class SyncGroupLogListResult(_serialization.Model): """A list of sync group log properties. Variables are only populated by the server, and will be ignored when sending a request. @@ -18988,34 +18609,31 @@ class SyncGroupLogListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[SyncGroupLogProperties]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[SyncGroupLogProperties]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SyncGroupLogListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class SyncGroupLogProperties(msrest.serialization.Model): +class SyncGroupLogProperties(_serialization.Model): """Properties of an Azure SQL Database sync group log. Variables are only populated by the server, and will be ignored when sending a request. :ivar timestamp: Timestamp of the sync group log. :vartype timestamp: ~datetime.datetime - :ivar type: Type of the sync group log. Known values are: "All", "Error", "Warning", "Success". + :ivar type: Type of the sync group log. Known values are: "All", "Error", "Warning", and + "Success". :vartype type: str or ~azure.mgmt.sql.models.SyncGroupLogType :ivar source: Source of the sync group log. :vartype source: str @@ -19028,30 +18646,26 @@ class SyncGroupLogProperties(msrest.serialization.Model): """ _validation = { - 'timestamp': {'readonly': True}, - 'type': {'readonly': True}, - 'source': {'readonly': True}, - 'details': {'readonly': True}, - 'tracing_id': {'readonly': True}, - 'operation_status': {'readonly': True}, + "timestamp": {"readonly": True}, + "type": {"readonly": True}, + "source": {"readonly": True}, + "details": {"readonly": True}, + "tracing_id": {"readonly": True}, + "operation_status": {"readonly": True}, } _attribute_map = { - 'timestamp': {'key': 'timestamp', 'type': 'iso-8601'}, - 'type': {'key': 'type', 'type': 'str'}, - 'source': {'key': 'source', 'type': 'str'}, - 'details': {'key': 'details', 'type': 'str'}, - 'tracing_id': {'key': 'tracingId', 'type': 'str'}, - 'operation_status': {'key': 'operationStatus', 'type': 'str'}, + "timestamp": {"key": "timestamp", "type": "iso-8601"}, + "type": {"key": "type", "type": "str"}, + "source": {"key": "source", "type": "str"}, + "details": {"key": "details", "type": "str"}, + "tracing_id": {"key": "tracingId", "type": "str"}, + "operation_status": {"key": "operationStatus", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SyncGroupLogProperties, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.timestamp = None self.type = None self.source = None @@ -19060,7 +18674,7 @@ def __init__( self.operation_status = None -class SyncGroupSchema(msrest.serialization.Model): +class SyncGroupSchema(_serialization.Model): """Properties of sync group schema. :ivar tables: List of tables in sync group schema. @@ -19070,8 +18684,8 @@ class SyncGroupSchema(msrest.serialization.Model): """ _attribute_map = { - 'tables': {'key': 'tables', 'type': '[SyncGroupSchemaTable]'}, - 'master_sync_member_name': {'key': 'masterSyncMemberName', 'type': 'str'}, + "tables": {"key": "tables", "type": "[SyncGroupSchemaTable]"}, + "master_sync_member_name": {"key": "masterSyncMemberName", "type": "str"}, } def __init__( @@ -19087,12 +18701,12 @@ def __init__( :keyword master_sync_member_name: Name of master sync member where the schema is from. :paramtype master_sync_member_name: str """ - super(SyncGroupSchema, self).__init__(**kwargs) + super().__init__(**kwargs) self.tables = tables self.master_sync_member_name = master_sync_member_name -class SyncGroupSchemaTable(msrest.serialization.Model): +class SyncGroupSchemaTable(_serialization.Model): """Properties of table in sync group schema. :ivar columns: List of columns in sync group schema. @@ -19102,8 +18716,8 @@ class SyncGroupSchemaTable(msrest.serialization.Model): """ _attribute_map = { - 'columns': {'key': 'columns', 'type': '[SyncGroupSchemaTableColumn]'}, - 'quoted_name': {'key': 'quotedName', 'type': 'str'}, + "columns": {"key": "columns", "type": "[SyncGroupSchemaTableColumn]"}, + "quoted_name": {"key": "quotedName", "type": "str"}, } def __init__( @@ -19119,12 +18733,12 @@ def __init__( :keyword quoted_name: Quoted name of sync group schema table. :paramtype quoted_name: str """ - super(SyncGroupSchemaTable, self).__init__(**kwargs) + super().__init__(**kwargs) self.columns = columns self.quoted_name = quoted_name -class SyncGroupSchemaTableColumn(msrest.serialization.Model): +class SyncGroupSchemaTableColumn(_serialization.Model): """Properties of column in sync group table. :ivar quoted_name: Quoted name of sync group table column. @@ -19136,9 +18750,9 @@ class SyncGroupSchemaTableColumn(msrest.serialization.Model): """ _attribute_map = { - 'quoted_name': {'key': 'quotedName', 'type': 'str'}, - 'data_size': {'key': 'dataSize', 'type': 'str'}, - 'data_type': {'key': 'dataType', 'type': 'str'}, + "quoted_name": {"key": "quotedName", "type": "str"}, + "data_size": {"key": "dataSize", "type": "str"}, + "data_type": {"key": "dataType", "type": "str"}, } def __init__( @@ -19157,13 +18771,13 @@ def __init__( :keyword data_type: Data type of the column. :paramtype data_type: str """ - super(SyncGroupSchemaTableColumn, self).__init__(**kwargs) + super().__init__(**kwargs) self.quoted_name = quoted_name self.data_size = data_size self.data_type = data_type -class SyncMember(ProxyResource): +class SyncMember(ProxyResource): # pylint: disable=too-many-instance-attributes """An Azure SQL Database sync member. Variables are only populated by the server, and will be ignored when sending a request. @@ -19174,7 +18788,7 @@ class SyncMember(ProxyResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar database_type: Database type of the sync member. Known values are: "AzureSqlDatabase", + :ivar database_type: Database type of the sync member. Known values are: "AzureSqlDatabase" and "SqlServerDatabase". :vartype database_type: str or ~azure.mgmt.sql.models.SyncMemberDbType :ivar sync_agent_id: ARM resource id of the sync agent in the sync member. @@ -19198,40 +18812,43 @@ class SyncMember(ProxyResource): :ivar password: Password of the member database in the sync member. :vartype password: str :ivar sync_direction: Sync direction of the sync member. Known values are: "Bidirectional", - "OneWayMemberToHub", "OneWayHubToMember". + "OneWayMemberToHub", and "OneWayHubToMember". :vartype sync_direction: str or ~azure.mgmt.sql.models.SyncDirection :ivar sync_state: Sync state of the sync member. Known values are: "SyncInProgress", "SyncSucceeded", "SyncFailed", "DisabledTombstoneCleanup", "DisabledBackupRestore", "SyncSucceededWithWarnings", "SyncCancelling", "SyncCancelled", "UnProvisioned", "Provisioning", "Provisioned", "ProvisionFailed", "DeProvisioning", "DeProvisioned", - "DeProvisionFailed", "Reprovisioning", "ReprovisionFailed", "UnReprovisioned". + "DeProvisionFailed", "Reprovisioning", "ReprovisionFailed", and "UnReprovisioned". :vartype sync_state: str or ~azure.mgmt.sql.models.SyncMemberState """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'private_endpoint_name': {'readonly': True}, - 'sync_state': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "private_endpoint_name": {"readonly": True}, + "sync_state": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'database_type': {'key': 'properties.databaseType', 'type': 'str'}, - 'sync_agent_id': {'key': 'properties.syncAgentId', 'type': 'str'}, - 'sql_server_database_id': {'key': 'properties.sqlServerDatabaseId', 'type': 'str'}, - 'sync_member_azure_database_resource_id': {'key': 'properties.syncMemberAzureDatabaseResourceId', 'type': 'str'}, - 'use_private_link_connection': {'key': 'properties.usePrivateLinkConnection', 'type': 'bool'}, - 'private_endpoint_name': {'key': 'properties.privateEndpointName', 'type': 'str'}, - 'server_name': {'key': 'properties.serverName', 'type': 'str'}, - 'database_name': {'key': 'properties.databaseName', 'type': 'str'}, - 'user_name': {'key': 'properties.userName', 'type': 'str'}, - 'password': {'key': 'properties.password', 'type': 'str'}, - 'sync_direction': {'key': 'properties.syncDirection', 'type': 'str'}, - 'sync_state': {'key': 'properties.syncState', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "database_type": {"key": "properties.databaseType", "type": "str"}, + "sync_agent_id": {"key": "properties.syncAgentId", "type": "str"}, + "sql_server_database_id": {"key": "properties.sqlServerDatabaseId", "type": "str"}, + "sync_member_azure_database_resource_id": { + "key": "properties.syncMemberAzureDatabaseResourceId", + "type": "str", + }, + "use_private_link_connection": {"key": "properties.usePrivateLinkConnection", "type": "bool"}, + "private_endpoint_name": {"key": "properties.privateEndpointName", "type": "str"}, + "server_name": {"key": "properties.serverName", "type": "str"}, + "database_name": {"key": "properties.databaseName", "type": "str"}, + "user_name": {"key": "properties.userName", "type": "str"}, + "password": {"key": "properties.password", "type": "str"}, + "sync_direction": {"key": "properties.syncDirection", "type": "str"}, + "sync_state": {"key": "properties.syncState", "type": "str"}, } def __init__( @@ -19250,8 +18867,8 @@ def __init__( **kwargs ): """ - :keyword database_type: Database type of the sync member. Known values are: "AzureSqlDatabase", - "SqlServerDatabase". + :keyword database_type: Database type of the sync member. Known values are: "AzureSqlDatabase" + and "SqlServerDatabase". :paramtype database_type: str or ~azure.mgmt.sql.models.SyncMemberDbType :keyword sync_agent_id: ARM resource id of the sync agent in the sync member. :paramtype sync_agent_id: str @@ -19271,10 +18888,10 @@ def __init__( :keyword password: Password of the member database in the sync member. :paramtype password: str :keyword sync_direction: Sync direction of the sync member. Known values are: "Bidirectional", - "OneWayMemberToHub", "OneWayHubToMember". + "OneWayMemberToHub", and "OneWayHubToMember". :paramtype sync_direction: str or ~azure.mgmt.sql.models.SyncDirection """ - super(SyncMember, self).__init__(**kwargs) + super().__init__(**kwargs) self.database_type = database_type self.sync_agent_id = sync_agent_id self.sql_server_database_id = sql_server_database_id @@ -19289,7 +18906,7 @@ def __init__( self.sync_state = None -class SyncMemberListResult(msrest.serialization.Model): +class SyncMemberListResult(_serialization.Model): """A list of Azure SQL Database sync members. Variables are only populated by the server, and will be ignored when sending a request. @@ -19301,52 +18918,48 @@ class SyncMemberListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[SyncMember]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[SyncMember]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(SyncMemberListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class SystemData(msrest.serialization.Model): +class SystemData(_serialization.Model): """Metadata pertaining to creation and last modification of the resource. :ivar created_by: The identity that created the resource. :vartype created_by: str :ivar created_by_type: The type of identity that created the resource. Known values are: - "User", "Application", "ManagedIdentity", "Key". + "User", "Application", "ManagedIdentity", and "Key". :vartype created_by_type: str or ~azure.mgmt.sql.models.CreatedByType :ivar created_at: The timestamp of resource creation (UTC). :vartype created_at: ~datetime.datetime :ivar last_modified_by: The identity that last modified the resource. :vartype last_modified_by: str :ivar last_modified_by_type: The type of identity that last modified the resource. Known values - are: "User", "Application", "ManagedIdentity", "Key". + are: "User", "Application", "ManagedIdentity", and "Key". :vartype last_modified_by_type: str or ~azure.mgmt.sql.models.CreatedByType :ivar last_modified_at: The timestamp of resource last modification (UTC). :vartype last_modified_at: ~datetime.datetime """ _attribute_map = { - 'created_by': {'key': 'createdBy', 'type': 'str'}, - 'created_by_type': {'key': 'createdByType', 'type': 'str'}, - 'created_at': {'key': 'createdAt', 'type': 'iso-8601'}, - 'last_modified_by': {'key': 'lastModifiedBy', 'type': 'str'}, - 'last_modified_by_type': {'key': 'lastModifiedByType', 'type': 'str'}, - 'last_modified_at': {'key': 'lastModifiedAt', 'type': 'iso-8601'}, + "created_by": {"key": "createdBy", "type": "str"}, + "created_by_type": {"key": "createdByType", "type": "str"}, + "created_at": {"key": "createdAt", "type": "iso-8601"}, + "last_modified_by": {"key": "lastModifiedBy", "type": "str"}, + "last_modified_by_type": {"key": "lastModifiedByType", "type": "str"}, + "last_modified_at": {"key": "lastModifiedAt", "type": "iso-8601"}, } def __init__( @@ -19364,19 +18977,19 @@ def __init__( :keyword created_by: The identity that created the resource. :paramtype created_by: str :keyword created_by_type: The type of identity that created the resource. Known values are: - "User", "Application", "ManagedIdentity", "Key". + "User", "Application", "ManagedIdentity", and "Key". :paramtype created_by_type: str or ~azure.mgmt.sql.models.CreatedByType :keyword created_at: The timestamp of resource creation (UTC). :paramtype created_at: ~datetime.datetime :keyword last_modified_by: The identity that last modified the resource. :paramtype last_modified_by: str :keyword last_modified_by_type: The type of identity that last modified the resource. Known - values are: "User", "Application", "ManagedIdentity", "Key". + values are: "User", "Application", "ManagedIdentity", and "Key". :paramtype last_modified_by_type: str or ~azure.mgmt.sql.models.CreatedByType :keyword last_modified_at: The timestamp of resource last modification (UTC). :paramtype last_modified_at: ~datetime.datetime """ - super(SystemData, self).__init__(**kwargs) + super().__init__(**kwargs) self.created_by = created_by self.created_by_type = created_by_type self.created_at = created_at @@ -19403,33 +19016,27 @@ class TdeCertificate(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'private_blob': {'key': 'properties.privateBlob', 'type': 'str'}, - 'cert_password': {'key': 'properties.certPassword', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "private_blob": {"key": "properties.privateBlob", "type": "str"}, + "cert_password": {"key": "properties.certPassword", "type": "str"}, } - def __init__( - self, - *, - private_blob: Optional[str] = None, - cert_password: Optional[str] = None, - **kwargs - ): + def __init__(self, *, private_blob: Optional[str] = None, cert_password: Optional[str] = None, **kwargs): """ :keyword private_blob: The base64 encoded certificate private blob. :paramtype private_blob: str :keyword cert_password: The certificate password. :paramtype cert_password: str """ - super(TdeCertificate, self).__init__(**kwargs) + super().__init__(**kwargs) self.private_blob = private_blob self.cert_password = cert_password @@ -19452,33 +19059,29 @@ class TimeZone(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'time_zone_id': {'readonly': True}, - 'display_name': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "time_zone_id": {"readonly": True}, + "display_name": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'time_zone_id': {'key': 'properties.timeZoneId', 'type': 'str'}, - 'display_name': {'key': 'properties.displayName', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "time_zone_id": {"key": "properties.timeZoneId", "type": "str"}, + "display_name": {"key": "properties.displayName", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(TimeZone, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.time_zone_id = None self.display_name = None -class TimeZoneListResult(msrest.serialization.Model): +class TimeZoneListResult(_serialization.Model): """A list of time zones. Variables are only populated by the server, and will be ignored when sending a request. @@ -19490,27 +19093,23 @@ class TimeZoneListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[TimeZone]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[TimeZone]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(TimeZoneListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class TopQueries(msrest.serialization.Model): +class TopQueries(_serialization.Model): """TopQueries. Variables are only populated by the server, and will be ignored when sending a request. @@ -19521,7 +19120,7 @@ class TopQueries(msrest.serialization.Model): :vartype aggregation_function: str :ivar observation_metric: Metric used to rank queries. :vartype observation_metric: str - :ivar interval_type: Interval type (length). Known values are: "PT1H", "P1D". + :ivar interval_type: Interval type (length). Known values are: "PT1H" and "P1D". :vartype interval_type: str or ~azure.mgmt.sql.models.QueryTimeGrainType :ivar start_time: The start time for the metric (ISO-8601 format). :vartype start_time: str @@ -19532,35 +19131,30 @@ class TopQueries(msrest.serialization.Model): """ _validation = { - 'number_of_queries': {'readonly': True}, - 'aggregation_function': {'readonly': True}, - 'observation_metric': {'readonly': True}, - 'interval_type': {'readonly': True}, - 'start_time': {'readonly': True}, - 'end_time': {'readonly': True}, + "number_of_queries": {"readonly": True}, + "aggregation_function": {"readonly": True}, + "observation_metric": {"readonly": True}, + "interval_type": {"readonly": True}, + "start_time": {"readonly": True}, + "end_time": {"readonly": True}, } _attribute_map = { - 'number_of_queries': {'key': 'numberOfQueries', 'type': 'int'}, - 'aggregation_function': {'key': 'aggregationFunction', 'type': 'str'}, - 'observation_metric': {'key': 'observationMetric', 'type': 'str'}, - 'interval_type': {'key': 'intervalType', 'type': 'str'}, - 'start_time': {'key': 'startTime', 'type': 'str'}, - 'end_time': {'key': 'endTime', 'type': 'str'}, - 'queries': {'key': 'queries', 'type': '[QueryStatisticsProperties]'}, + "number_of_queries": {"key": "numberOfQueries", "type": "int"}, + "aggregation_function": {"key": "aggregationFunction", "type": "str"}, + "observation_metric": {"key": "observationMetric", "type": "str"}, + "interval_type": {"key": "intervalType", "type": "str"}, + "start_time": {"key": "startTime", "type": "str"}, + "end_time": {"key": "endTime", "type": "str"}, + "queries": {"key": "queries", "type": "[QueryStatisticsProperties]"}, } - def __init__( - self, - *, - queries: Optional[List["_models.QueryStatisticsProperties"]] = None, - **kwargs - ): + def __init__(self, *, queries: Optional[List["_models.QueryStatisticsProperties"]] = None, **kwargs): """ :keyword queries: List of top resource consuming queries with appropriate metric data. :paramtype queries: list[~azure.mgmt.sql.models.QueryStatisticsProperties] """ - super(TopQueries, self).__init__(**kwargs) + super().__init__(**kwargs) self.number_of_queries = None self.aggregation_function = None self.observation_metric = None @@ -19570,7 +19164,7 @@ def __init__( self.queries = queries -class TopQueriesListResult(msrest.serialization.Model): +class TopQueriesListResult(_serialization.Model): """A list of top resource consuming queries on managed instance. Variables are only populated by the server, and will be ignored when sending a request. @@ -19582,37 +19176,33 @@ class TopQueriesListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[TopQueries]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[TopQueries]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(TopQueriesListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class UpdateLongTermRetentionBackupParameters(msrest.serialization.Model): +class UpdateLongTermRetentionBackupParameters(_serialization.Model): """Contains the information necessary to perform long term retention backup update operation. :ivar requested_backup_storage_redundancy: The storage redundancy type of the copied backup. - Known values are: "Geo", "Local", "Zone", "GeoZone". + Known values are: "Geo", "Local", "Zone", and "GeoZone". :vartype requested_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy """ _attribute_map = { - 'requested_backup_storage_redundancy': {'key': 'properties.requestedBackupStorageRedundancy', 'type': 'str'}, + "requested_backup_storage_redundancy": {"key": "properties.requestedBackupStorageRedundancy", "type": "str"}, } def __init__( @@ -19623,11 +19213,11 @@ def __init__( ): """ :keyword requested_backup_storage_redundancy: The storage redundancy type of the copied backup. - Known values are: "Geo", "Local", "Zone", "GeoZone". + Known values are: "Geo", "Local", "Zone", and "GeoZone". :paramtype requested_backup_storage_redundancy: str or ~azure.mgmt.sql.models.BackupStorageRedundancy """ - super(UpdateLongTermRetentionBackupParameters, self).__init__(**kwargs) + super().__init__(**kwargs) self.requested_backup_storage_redundancy = requested_backup_storage_redundancy @@ -19642,35 +19232,32 @@ class UpdateManagedInstanceDnsServersOperation(ProxyResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar status: The status of the DNS refresh operation. Known values are: "Succeeded", "Failed". + :ivar status: The status of the DNS refresh operation. Known values are: "Succeeded" and + "Failed". :vartype status: str or ~azure.mgmt.sql.models.DnsRefreshConfigurationPropertiesStatus """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'status': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "status": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'status': {'key': 'properties.status', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "status": {"key": "properties.status", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(UpdateManagedInstanceDnsServersOperation, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.status = None -class UpsertManagedServerOperationParameters(msrest.serialization.Model): +class UpsertManagedServerOperationParameters(_serialization.Model): """UpsertManagedServerOperationParameters. :ivar family: @@ -19684,10 +19271,10 @@ class UpsertManagedServerOperationParameters(msrest.serialization.Model): """ _attribute_map = { - 'family': {'key': 'family', 'type': 'str'}, - 'tier': {'key': 'tier', 'type': 'str'}, - 'v_cores': {'key': 'vCores', 'type': 'int'}, - 'storage_size_in_gb': {'key': 'storageSizeInGB', 'type': 'int'}, + "family": {"key": "family", "type": "str"}, + "tier": {"key": "tier", "type": "str"}, + "v_cores": {"key": "vCores", "type": "int"}, + "storage_size_in_gb": {"key": "storageSizeInGB", "type": "int"}, } def __init__( @@ -19709,14 +19296,14 @@ def __init__( :keyword storage_size_in_gb: :paramtype storage_size_in_gb: int """ - super(UpsertManagedServerOperationParameters, self).__init__(**kwargs) + super().__init__(**kwargs) self.family = family self.tier = tier self.v_cores = v_cores self.storage_size_in_gb = storage_size_in_gb -class UpsertManagedServerOperationStep(msrest.serialization.Model): +class UpsertManagedServerOperationStep(_serialization.Model): """UpsertManagedServerOperationStep. :ivar order: @@ -19724,14 +19311,14 @@ class UpsertManagedServerOperationStep(msrest.serialization.Model): :ivar name: :vartype name: str :ivar status: Known values are: "NotStarted", "InProgress", "SlowedDown", "Completed", - "Failed", "Canceled". + "Failed", and "Canceled". :vartype status: str or ~azure.mgmt.sql.models.UpsertManagedServerOperationStepStatus """ _attribute_map = { - 'order': {'key': 'order', 'type': 'int'}, - 'name': {'key': 'name', 'type': 'str'}, - 'status': {'key': 'status', 'type': 'str'}, + "order": {"key": "order", "type": "int"}, + "name": {"key": "name", "type": "str"}, + "status": {"key": "status", "type": "str"}, } def __init__( @@ -19748,16 +19335,16 @@ def __init__( :keyword name: :paramtype name: str :keyword status: Known values are: "NotStarted", "InProgress", "SlowedDown", "Completed", - "Failed", "Canceled". + "Failed", and "Canceled". :paramtype status: str or ~azure.mgmt.sql.models.UpsertManagedServerOperationStepStatus """ - super(UpsertManagedServerOperationStep, self).__init__(**kwargs) + super().__init__(**kwargs) self.order = order self.name = name self.status = status -class Usage(msrest.serialization.Model): +class Usage(_serialization.Model): """ARM usage. Variables are only populated by the server, and will be ignored when sending a request. @@ -19779,32 +19366,28 @@ class Usage(msrest.serialization.Model): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'unit': {'readonly': True}, - 'current_value': {'readonly': True}, - 'limit': {'readonly': True}, - 'requested_limit': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "unit": {"readonly": True}, + "current_value": {"readonly": True}, + "limit": {"readonly": True}, + "requested_limit": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'Name'}, - 'type': {'key': 'type', 'type': 'str'}, - 'unit': {'key': 'unit', 'type': 'str'}, - 'current_value': {'key': 'currentValue', 'type': 'int'}, - 'limit': {'key': 'limit', 'type': 'int'}, - 'requested_limit': {'key': 'requestedLimit', 'type': 'int'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "Name"}, + "type": {"key": "type", "type": "str"}, + "unit": {"key": "unit", "type": "str"}, + "current_value": {"key": "currentValue", "type": "int"}, + "limit": {"key": "limit", "type": "int"}, + "requested_limit": {"key": "requestedLimit", "type": "int"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(Usage, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.id = None self.name = None self.type = None @@ -19814,7 +19397,7 @@ def __init__( self.requested_limit = None -class UsageListResult(msrest.serialization.Model): +class UsageListResult(_serialization.Model): """A list of usages. Variables are only populated by the server, and will be ignored when sending a request. @@ -19826,27 +19409,23 @@ class UsageListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[Usage]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[Usage]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(UsageListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class UserIdentity(msrest.serialization.Model): +class UserIdentity(_serialization.Model): """Azure Active Directory identity configuration for a resource. Variables are only populated by the server, and will be ignored when sending a request. @@ -19858,22 +19437,18 @@ class UserIdentity(msrest.serialization.Model): """ _validation = { - 'principal_id': {'readonly': True}, - 'client_id': {'readonly': True}, + "principal_id": {"readonly": True}, + "client_id": {"readonly": True}, } _attribute_map = { - 'principal_id': {'key': 'principalId', 'type': 'str'}, - 'client_id': {'key': 'clientId', 'type': 'str'}, + "principal_id": {"key": "principalId", "type": "str"}, + "client_id": {"key": "clientId", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(UserIdentity, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.principal_id = None self.client_id = None @@ -19891,9 +19466,9 @@ class VirtualCluster(TrackedResource): :vartype name: str :ivar type: Resource type. :vartype type: str - :ivar location: Required. Resource location. + :ivar location: Resource location. Required. :vartype location: str - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar subnet_id: Subnet resource ID for the virtual cluster. :vartype subnet_id: str @@ -19908,24 +19483,24 @@ class VirtualCluster(TrackedResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'location': {'required': True}, - 'subnet_id': {'readonly': True}, - 'child_resources': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "location": {"required": True}, + "subnet_id": {"readonly": True}, + "child_resources": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, - 'tags': {'key': 'tags', 'type': '{str}'}, - 'subnet_id': {'key': 'properties.subnetId', 'type': 'str'}, - 'family': {'key': 'properties.family', 'type': 'str'}, - 'child_resources': {'key': 'properties.childResources', 'type': '[str]'}, - 'maintenance_configuration_id': {'key': 'properties.maintenanceConfigurationId', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "location": {"key": "location", "type": "str"}, + "tags": {"key": "tags", "type": "{str}"}, + "subnet_id": {"key": "properties.subnetId", "type": "str"}, + "family": {"key": "properties.family", "type": "str"}, + "child_resources": {"key": "properties.childResources", "type": "[str]"}, + "maintenance_configuration_id": {"key": "properties.maintenanceConfigurationId", "type": "str"}, } def __init__( @@ -19938,9 +19513,9 @@ def __init__( **kwargs ): """ - :keyword location: Required. Resource location. + :keyword location: Resource location. Required. :paramtype location: str - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] :keyword family: If the service has different generations of hardware, for the same SKU, then that can be captured here. @@ -19949,14 +19524,14 @@ def __init__( virtual cluster. :paramtype maintenance_configuration_id: str """ - super(VirtualCluster, self).__init__(location=location, tags=tags, **kwargs) + super().__init__(location=location, tags=tags, **kwargs) self.subnet_id = None self.family = family self.child_resources = None self.maintenance_configuration_id = maintenance_configuration_id -class VirtualClusterListResult(msrest.serialization.Model): +class VirtualClusterListResult(_serialization.Model): """A list of virtual clusters. Variables are only populated by the server, and will be ignored when sending a request. @@ -19968,32 +19543,28 @@ class VirtualClusterListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[VirtualCluster]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[VirtualCluster]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(VirtualClusterListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class VirtualClusterUpdate(msrest.serialization.Model): +class VirtualClusterUpdate(_serialization.Model): """An update request for an Azure SQL Database virtual cluster. Variables are only populated by the server, and will be ignored when sending a request. - :ivar tags: A set of tags. Resource tags. + :ivar tags: Resource tags. :vartype tags: dict[str, str] :ivar subnet_id: Subnet resource ID for the virtual cluster. :vartype subnet_id: str @@ -20008,16 +19579,16 @@ class VirtualClusterUpdate(msrest.serialization.Model): """ _validation = { - 'subnet_id': {'readonly': True}, - 'child_resources': {'readonly': True}, + "subnet_id": {"readonly": True}, + "child_resources": {"readonly": True}, } _attribute_map = { - 'tags': {'key': 'tags', 'type': '{str}'}, - 'subnet_id': {'key': 'properties.subnetId', 'type': 'str'}, - 'family': {'key': 'properties.family', 'type': 'str'}, - 'child_resources': {'key': 'properties.childResources', 'type': '[str]'}, - 'maintenance_configuration_id': {'key': 'properties.maintenanceConfigurationId', 'type': 'str'}, + "tags": {"key": "tags", "type": "{str}"}, + "subnet_id": {"key": "properties.subnetId", "type": "str"}, + "family": {"key": "properties.family", "type": "str"}, + "child_resources": {"key": "properties.childResources", "type": "[str]"}, + "maintenance_configuration_id": {"key": "properties.maintenanceConfigurationId", "type": "str"}, } def __init__( @@ -20029,7 +19600,7 @@ def __init__( **kwargs ): """ - :keyword tags: A set of tags. Resource tags. + :keyword tags: Resource tags. :paramtype tags: dict[str, str] :keyword family: If the service has different generations of hardware, for the same SKU, then that can be captured here. @@ -20038,7 +19609,7 @@ def __init__( virtual cluster. :paramtype maintenance_configuration_id: str """ - super(VirtualClusterUpdate, self).__init__(**kwargs) + super().__init__(**kwargs) self.tags = tags self.subnet_id = None self.family = family @@ -20063,24 +19634,24 @@ class VirtualNetworkRule(ProxyResource): vnet service endpoint enabled. :vartype ignore_missing_vnet_service_endpoint: bool :ivar state: Virtual Network Rule State. Known values are: "Initializing", "InProgress", - "Ready", "Failed", "Deleting", "Unknown". + "Ready", "Failed", "Deleting", and "Unknown". :vartype state: str or ~azure.mgmt.sql.models.VirtualNetworkRuleState """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'state': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "state": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'virtual_network_subnet_id': {'key': 'properties.virtualNetworkSubnetId', 'type': 'str'}, - 'ignore_missing_vnet_service_endpoint': {'key': 'properties.ignoreMissingVnetServiceEndpoint', 'type': 'bool'}, - 'state': {'key': 'properties.state', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "virtual_network_subnet_id": {"key": "properties.virtualNetworkSubnetId", "type": "str"}, + "ignore_missing_vnet_service_endpoint": {"key": "properties.ignoreMissingVnetServiceEndpoint", "type": "bool"}, + "state": {"key": "properties.state", "type": "str"}, } def __init__( @@ -20097,13 +19668,13 @@ def __init__( has vnet service endpoint enabled. :paramtype ignore_missing_vnet_service_endpoint: bool """ - super(VirtualNetworkRule, self).__init__(**kwargs) + super().__init__(**kwargs) self.virtual_network_subnet_id = virtual_network_subnet_id self.ignore_missing_vnet_service_endpoint = ignore_missing_vnet_service_endpoint self.state = None -class VirtualNetworkRuleListResult(msrest.serialization.Model): +class VirtualNetworkRuleListResult(_serialization.Model): """A list of virtual network rules. Variables are only populated by the server, and will be ignored when sending a request. @@ -20115,27 +19686,23 @@ class VirtualNetworkRuleListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[VirtualNetworkRule]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[VirtualNetworkRule]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(VirtualNetworkRuleListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None -class VulnerabilityAssessmentRecurringScansProperties(msrest.serialization.Model): +class VulnerabilityAssessmentRecurringScansProperties(_serialization.Model): """Properties of a Vulnerability Assessment recurring scans. :ivar is_enabled: Recurring scans state. @@ -20148,16 +19715,16 @@ class VulnerabilityAssessmentRecurringScansProperties(msrest.serialization.Model """ _attribute_map = { - 'is_enabled': {'key': 'isEnabled', 'type': 'bool'}, - 'email_subscription_admins': {'key': 'emailSubscriptionAdmins', 'type': 'bool'}, - 'emails': {'key': 'emails', 'type': '[str]'}, + "is_enabled": {"key": "isEnabled", "type": "bool"}, + "email_subscription_admins": {"key": "emailSubscriptionAdmins", "type": "bool"}, + "emails": {"key": "emails", "type": "[str]"}, } def __init__( self, *, is_enabled: Optional[bool] = None, - email_subscription_admins: Optional[bool] = True, + email_subscription_admins: bool = True, emails: Optional[List[str]] = None, **kwargs ): @@ -20170,13 +19737,13 @@ def __init__( :keyword emails: Specifies an array of e-mail addresses to which the scan notification is sent. :paramtype emails: list[str] """ - super(VulnerabilityAssessmentRecurringScansProperties, self).__init__(**kwargs) + super().__init__(**kwargs) self.is_enabled = is_enabled self.email_subscription_admins = email_subscription_admins self.emails = emails -class VulnerabilityAssessmentScanError(msrest.serialization.Model): +class VulnerabilityAssessmentScanError(_serialization.Model): """Properties of a vulnerability assessment scan error. Variables are only populated by the server, and will be ignored when sending a request. @@ -20188,27 +19755,23 @@ class VulnerabilityAssessmentScanError(msrest.serialization.Model): """ _validation = { - 'code': {'readonly': True}, - 'message': {'readonly': True}, + "code": {"readonly": True}, + "message": {"readonly": True}, } _attribute_map = { - 'code': {'key': 'code', 'type': 'str'}, - 'message': {'key': 'message', 'type': 'str'}, + "code": {"key": "code", "type": "str"}, + "message": {"key": "message", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(VulnerabilityAssessmentScanError, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.code = None self.message = None -class VulnerabilityAssessmentScanRecord(ProxyResource): +class VulnerabilityAssessmentScanRecord(ProxyResource): # pylint: disable=too-many-instance-attributes """A vulnerability assessment scan record. Variables are only populated by the server, and will be ignored when sending a request. @@ -20221,9 +19784,9 @@ class VulnerabilityAssessmentScanRecord(ProxyResource): :vartype type: str :ivar scan_id: The scan ID. :vartype scan_id: str - :ivar trigger_type: The scan trigger type. Known values are: "OnDemand", "Recurring". + :ivar trigger_type: The scan trigger type. Known values are: "OnDemand" and "Recurring". :vartype trigger_type: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentScanTriggerType - :ivar state: The scan status. Known values are: "Passed", "Failed", "FailedToRun", + :ivar state: The scan status. Known values are: "Passed", "Failed", "FailedToRun", and "InProgress". :vartype state: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentScanState :ivar start_time: The scan start time (UTC). @@ -20239,40 +19802,36 @@ class VulnerabilityAssessmentScanRecord(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'scan_id': {'readonly': True}, - 'trigger_type': {'readonly': True}, - 'state': {'readonly': True}, - 'start_time': {'readonly': True}, - 'end_time': {'readonly': True}, - 'errors': {'readonly': True}, - 'storage_container_path': {'readonly': True}, - 'number_of_failed_security_checks': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "scan_id": {"readonly": True}, + "trigger_type": {"readonly": True}, + "state": {"readonly": True}, + "start_time": {"readonly": True}, + "end_time": {"readonly": True}, + "errors": {"readonly": True}, + "storage_container_path": {"readonly": True}, + "number_of_failed_security_checks": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'scan_id': {'key': 'properties.scanId', 'type': 'str'}, - 'trigger_type': {'key': 'properties.triggerType', 'type': 'str'}, - 'state': {'key': 'properties.state', 'type': 'str'}, - 'start_time': {'key': 'properties.startTime', 'type': 'iso-8601'}, - 'end_time': {'key': 'properties.endTime', 'type': 'iso-8601'}, - 'errors': {'key': 'properties.errors', 'type': '[VulnerabilityAssessmentScanError]'}, - 'storage_container_path': {'key': 'properties.storageContainerPath', 'type': 'str'}, - 'number_of_failed_security_checks': {'key': 'properties.numberOfFailedSecurityChecks', 'type': 'int'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "scan_id": {"key": "properties.scanId", "type": "str"}, + "trigger_type": {"key": "properties.triggerType", "type": "str"}, + "state": {"key": "properties.state", "type": "str"}, + "start_time": {"key": "properties.startTime", "type": "iso-8601"}, + "end_time": {"key": "properties.endTime", "type": "iso-8601"}, + "errors": {"key": "properties.errors", "type": "[VulnerabilityAssessmentScanError]"}, + "storage_container_path": {"key": "properties.storageContainerPath", "type": "str"}, + "number_of_failed_security_checks": {"key": "properties.numberOfFailedSecurityChecks", "type": "int"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(VulnerabilityAssessmentScanRecord, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.scan_id = None self.trigger_type = None self.state = None @@ -20283,7 +19842,7 @@ def __init__( self.number_of_failed_security_checks = None -class VulnerabilityAssessmentScanRecordListResult(msrest.serialization.Model): +class VulnerabilityAssessmentScanRecordListResult(_serialization.Model): """A list of vulnerability assessment scan records. Variables are only populated by the server, and will be ignored when sending a request. @@ -20295,22 +19854,18 @@ class VulnerabilityAssessmentScanRecordListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[VulnerabilityAssessmentScanRecord]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[VulnerabilityAssessmentScanRecord]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(VulnerabilityAssessmentScanRecordListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -20341,21 +19896,21 @@ class WorkloadClassifier(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'member_name': {'key': 'properties.memberName', 'type': 'str'}, - 'label': {'key': 'properties.label', 'type': 'str'}, - 'context': {'key': 'properties.context', 'type': 'str'}, - 'start_time': {'key': 'properties.startTime', 'type': 'str'}, - 'end_time': {'key': 'properties.endTime', 'type': 'str'}, - 'importance': {'key': 'properties.importance', 'type': 'str'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "member_name": {"key": "properties.memberName", "type": "str"}, + "label": {"key": "properties.label", "type": "str"}, + "context": {"key": "properties.context", "type": "str"}, + "start_time": {"key": "properties.startTime", "type": "str"}, + "end_time": {"key": "properties.endTime", "type": "str"}, + "importance": {"key": "properties.importance", "type": "str"}, } def __init__( @@ -20383,7 +19938,7 @@ def __init__( :keyword importance: The workload classifier importance. :paramtype importance: str """ - super(WorkloadClassifier, self).__init__(**kwargs) + super().__init__(**kwargs) self.member_name = member_name self.label = label self.context = context @@ -20392,7 +19947,7 @@ def __init__( self.importance = importance -class WorkloadClassifierListResult(msrest.serialization.Model): +class WorkloadClassifierListResult(_serialization.Model): """A list of workload classifiers for a workload group. Variables are only populated by the server, and will be ignored when sending a request. @@ -20404,22 +19959,18 @@ class WorkloadClassifierListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[WorkloadClassifier]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[WorkloadClassifier]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(WorkloadClassifierListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None @@ -20450,21 +20001,21 @@ class WorkloadGroup(ProxyResource): """ _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, } _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'min_resource_percent': {'key': 'properties.minResourcePercent', 'type': 'int'}, - 'max_resource_percent': {'key': 'properties.maxResourcePercent', 'type': 'int'}, - 'min_resource_percent_per_request': {'key': 'properties.minResourcePercentPerRequest', 'type': 'float'}, - 'max_resource_percent_per_request': {'key': 'properties.maxResourcePercentPerRequest', 'type': 'float'}, - 'importance': {'key': 'properties.importance', 'type': 'str'}, - 'query_execution_timeout': {'key': 'properties.queryExecutionTimeout', 'type': 'int'}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "min_resource_percent": {"key": "properties.minResourcePercent", "type": "int"}, + "max_resource_percent": {"key": "properties.maxResourcePercent", "type": "int"}, + "min_resource_percent_per_request": {"key": "properties.minResourcePercentPerRequest", "type": "float"}, + "max_resource_percent_per_request": {"key": "properties.maxResourcePercentPerRequest", "type": "float"}, + "importance": {"key": "properties.importance", "type": "str"}, + "query_execution_timeout": {"key": "properties.queryExecutionTimeout", "type": "int"}, } def __init__( @@ -20492,7 +20043,7 @@ def __init__( :keyword query_execution_timeout: The workload group query execution timeout. :paramtype query_execution_timeout: int """ - super(WorkloadGroup, self).__init__(**kwargs) + super().__init__(**kwargs) self.min_resource_percent = min_resource_percent self.max_resource_percent = max_resource_percent self.min_resource_percent_per_request = min_resource_percent_per_request @@ -20501,7 +20052,7 @@ def __init__( self.query_execution_timeout = query_execution_timeout -class WorkloadGroupListResult(msrest.serialization.Model): +class WorkloadGroupListResult(_serialization.Model): """A list of workload groups. Variables are only populated by the server, and will be ignored when sending a request. @@ -20513,21 +20064,17 @@ class WorkloadGroupListResult(msrest.serialization.Model): """ _validation = { - 'value': {'readonly': True}, - 'next_link': {'readonly': True}, + "value": {"readonly": True}, + "next_link": {"readonly": True}, } _attribute_map = { - 'value': {'key': 'value', 'type': '[WorkloadGroup]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, + "value": {"key": "value", "type": "[WorkloadGroup]"}, + "next_link": {"key": "nextLink", "type": "str"}, } - def __init__( - self, - **kwargs - ): - """ - """ - super(WorkloadGroupListResult, self).__init__(**kwargs) + def __init__(self, **kwargs): + """ """ + super().__init__(**kwargs) self.value = None self.next_link = None diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/models/_patch.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/models/_patch.py index 0ad201a8c586e..f7dd32510333d 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/models/_patch.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/models/_patch.py @@ -10,6 +10,7 @@ __all__: List[str] = [] # Add all objects you want publicly available to users at this package level + def patch_sdk(): """Do not remove from this file. diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/models/_sql_management_client_enums.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/models/_sql_management_client_enums.py index 915d56476ceff..1f48b741b8d05 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/models/_sql_management_client_enums.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/models/_sql_management_client_enums.py @@ -11,19 +11,23 @@ class AdministratorName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """AdministratorName.""" ACTIVE_DIRECTORY = "ActiveDirectory" + class AdministratorType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Type of the sever administrator. - """ + """Type of the sever administrator.""" ACTIVE_DIRECTORY = "ActiveDirectory" + class AdvancedThreatProtectionName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """AdvancedThreatProtectionName.""" DEFAULT = "Default" + class AdvancedThreatProtectionState(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Specifies the state of the Advanced Threat Protection, whether it is enabled or disabled or a state has not been applied yet on the specific database or server. @@ -33,6 +37,7 @@ class AdvancedThreatProtectionState(str, Enum, metaclass=CaseInsensitiveEnumMeta ENABLED = "Enabled" DISABLED = "Disabled" + class AdvisorStatus(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Gets the status of availability of this advisor to customers. Possible values are 'GA', 'PublicPreview', 'LimitedPublicPreview' and 'PrivatePreview'. @@ -43,7 +48,9 @@ class AdvisorStatus(str, Enum, metaclass=CaseInsensitiveEnumMeta): LIMITED_PUBLIC_PREVIEW = "LimitedPublicPreview" PRIVATE_PREVIEW = "PrivatePreview" + class AggregationFunctionType(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """AggregationFunctionType.""" AVG = "avg" MIN = "min" @@ -51,19 +58,23 @@ class AggregationFunctionType(str, Enum, metaclass=CaseInsensitiveEnumMeta): STDEV = "stdev" SUM = "sum" + class AuthenticationName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """AuthenticationName.""" DEFAULT = "Default" + class AutoExecuteStatus(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Gets the auto-execute status (whether to let the system execute the recommendations) of this - advisor. Possible values are 'Enabled' and 'Disabled' + advisor. Possible values are 'Enabled' and 'Disabled'. """ ENABLED = "Enabled" DISABLED = "Disabled" DEFAULT = "Default" + class AutoExecuteStatusInheritedFrom(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Gets the resource from which current value of auto-execute status is inherited. Auto-execute status can be set on (and inherited from) different levels in the resource hierarchy. Possible @@ -77,9 +88,9 @@ class AutoExecuteStatusInheritedFrom(str, Enum, metaclass=CaseInsensitiveEnumMet ELASTIC_POOL = "ElasticPool" DATABASE = "Database" + class AutomaticTuningDisabledReason(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Reason description if desired and actual state are different. - """ + """Reason description if desired and actual state are different.""" DEFAULT = "Default" DISABLED = "Disabled" @@ -89,55 +100,56 @@ class AutomaticTuningDisabledReason(str, Enum, metaclass=CaseInsensitiveEnumMeta QUERY_STORE_READ_ONLY = "QueryStoreReadOnly" NOT_SUPPORTED = "NotSupported" + class AutomaticTuningMode(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Automatic tuning desired state. - """ + """Automatic tuning desired state.""" INHERIT = "Inherit" CUSTOM = "Custom" AUTO = "Auto" UNSPECIFIED = "Unspecified" + class AutomaticTuningOptionModeActual(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Automatic tuning option actual state. - """ + """Automatic tuning option actual state.""" OFF = "Off" ON = "On" + class AutomaticTuningOptionModeDesired(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Automatic tuning option desired state. - """ + """Automatic tuning option desired state.""" OFF = "Off" ON = "On" DEFAULT = "Default" + class AutomaticTuningServerMode(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Automatic tuning desired state. - """ + """Automatic tuning desired state.""" CUSTOM = "Custom" AUTO = "Auto" UNSPECIFIED = "Unspecified" + class AutomaticTuningServerReason(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Reason description if desired and actual state are different. - """ + """Reason description if desired and actual state are different.""" DEFAULT = "Default" DISABLED = "Disabled" AUTO_CONFIGURED = "AutoConfigured" + class BackupStorageRedundancy(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The storage account type used to store backups for this database. - """ + """The storage redundancy type of the copied backup.""" GEO = "Geo" LOCAL = "Local" ZONE = "Zone" GEO_ZONE = "GeoZone" + class BlobAuditingPolicyState(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Specifies the state of the audit. If state is Enabled, storageEndpoint or isAzureMonitorTargetEnabled are required. @@ -146,7 +158,9 @@ class BlobAuditingPolicyState(str, Enum, metaclass=CaseInsensitiveEnumMeta): ENABLED = "Enabled" DISABLED = "Disabled" + class CapabilityGroup(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """CapabilityGroup.""" SUPPORTED_EDITIONS = "supportedEditions" SUPPORTED_ELASTIC_POOL_EDITIONS = "supportedElasticPoolEditions" @@ -154,22 +168,23 @@ class CapabilityGroup(str, Enum, metaclass=CaseInsensitiveEnumMeta): SUPPORTED_INSTANCE_POOL_EDITIONS = "supportedInstancePoolEditions" SUPPORTED_MANAGED_INSTANCE_EDITIONS = "supportedManagedInstanceEditions" + class CapabilityStatus(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The status of the capability. - """ + """The status of the capability.""" VISIBLE = "Visible" AVAILABLE = "Available" DEFAULT = "Default" DISABLED = "Disabled" + class CatalogCollationType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Collation of the metadata catalog. - """ + """Collation of the metadata catalog.""" DATABASE_DEFAULT = "DATABASE_DEFAULT" SQL_LATIN1_GENERAL_CP1_CI_AS = "SQL_Latin1_General_CP1_CI_AS" + class CheckNameAvailabilityReason(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The reason code explaining why the name is unavailable. Will be undefined if the name is available. @@ -178,9 +193,9 @@ class CheckNameAvailabilityReason(str, Enum, metaclass=CaseInsensitiveEnumMeta): INVALID = "Invalid" ALREADY_EXISTS = "AlreadyExists" + class ColumnDataType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The column data type. - """ + """The column data type.""" IMAGE = "image" TEXT = "text" @@ -217,47 +232,50 @@ class ColumnDataType(str, Enum, metaclass=CaseInsensitiveEnumMeta): XML = "xml" SYSNAME = "sysname" + class ConnectionPolicyName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """ConnectionPolicyName.""" DEFAULT = "default" + class CreatedByType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The type of identity that created the resource. - """ + """The type of identity that created the resource.""" USER = "User" APPLICATION = "Application" MANAGED_IDENTITY = "ManagedIdentity" KEY = "Key" + class CreateMode(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Specifies the mode of database creation. - + Default: regular database creation. - + Copy: creates a database as a copy of an existing database. sourceDatabaseId must be specified as the resource ID of the source database. - + Secondary: creates a database as a secondary replica of an existing database. sourceDatabaseId must be specified as the resource ID of the existing primary database. - + PointInTimeRestore: Creates a database by restoring a point in time backup of an existing database. sourceDatabaseId must be specified as the resource ID of the existing database, and restorePointInTime must be specified. - + Recovery: Creates a database by restoring a geo-replicated backup. sourceDatabaseId must be specified as the recoverable database resource ID to restore. - + Restore: Creates a database by restoring a backup of a deleted database. sourceDatabaseId must be specified. If sourceDatabaseId is the database's original resource ID, then sourceDatabaseDeletionDate must be specified. Otherwise sourceDatabaseId must be the restorable dropped database resource ID and sourceDatabaseDeletionDate is ignored. restorePointInTime may also be specified to restore from an earlier point in time. - + RestoreLongTermRetentionBackup: Creates a database by restoring from a long term retention vault. recoveryServicesRecoveryPointResourceId must be specified as the recovery point resource ID. - + Copy, Secondary, and RestoreLongTermRetentionBackup are not supported for DataWarehouse edition. """ @@ -273,13 +291,14 @@ class CreateMode(str, Enum, metaclass=CaseInsensitiveEnumMeta): RESTORE_LONG_TERM_RETENTION_BACKUP = "RestoreLongTermRetentionBackup" ONLINE_SECONDARY = "OnlineSecondary" + class DatabaseIdentityType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The identity type - """ + """The identity type.""" NONE = "None" USER_ASSIGNED = "UserAssigned" + class DatabaseLicenseType(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The license type to apply for this database. ``LicenseIncluded`` if you need a license, or ``BasePrice`` if you have a license and are eligible for the Azure Hybrid Benefit. @@ -288,6 +307,7 @@ class DatabaseLicenseType(str, Enum, metaclass=CaseInsensitiveEnumMeta): LICENSE_INCLUDED = "LicenseIncluded" BASE_PRICE = "BasePrice" + class DatabaseReadScale(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The state of read-only routing. If enabled, connections that have application intent set to readonly in their connection string may be routed to a readonly secondary replica in the same @@ -297,15 +317,17 @@ class DatabaseReadScale(str, Enum, metaclass=CaseInsensitiveEnumMeta): ENABLED = "Enabled" DISABLED = "Disabled" + class DatabaseState(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """DatabaseState.""" ALL = "All" LIVE = "Live" DELETED = "Deleted" + class DatabaseStatus(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The status of the database. - """ + """The status of the database.""" ONLINE = "Online" RESTORING = "Restoring" @@ -332,9 +354,9 @@ class DatabaseStatus(str, Enum, metaclass=CaseInsensitiveEnumMeta): STOPPED = "Stopped" STARTING = "Starting" + class DataMaskingFunction(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The masking function that is used for the data masking rule. - """ + """The masking function that is used for the data masking rule.""" DEFAULT = "Default" CCN = "CCN" @@ -343,6 +365,7 @@ class DataMaskingFunction(str, Enum, metaclass=CaseInsensitiveEnumMeta): SSN = "SSN" TEXT = "Text" + class DataMaskingRuleState(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The rule state. Used to delete a rule. To delete an existing rule, specify the schemaName, tableName, columnName, maskingFunction, and specify ruleState as disabled. However, if the rule @@ -353,20 +376,22 @@ class DataMaskingRuleState(str, Enum, metaclass=CaseInsensitiveEnumMeta): DISABLED = "Disabled" ENABLED = "Enabled" + class DataMaskingState(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The state of the data masking policy. - """ + """The state of the data masking policy.""" DISABLED = "Disabled" ENABLED = "Enabled" + class DataWarehouseUserActivityName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """DataWarehouseUserActivityName.""" CURRENT = "current" + class DayOfWeek(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Day of maintenance window. - """ + """Day of maintenance window.""" SUNDAY = "Sunday" MONDAY = "Monday" @@ -376,6 +401,7 @@ class DayOfWeek(str, Enum, metaclass=CaseInsensitiveEnumMeta): FRIDAY = "Friday" SATURDAY = "Saturday" + class DiffBackupIntervalInHours(int, Enum, metaclass=CaseInsensitiveEnumMeta): """The differential backup interval in hours. This is how many interval hours between each differential backup will be supported. This is only applicable to live databases but not @@ -385,50 +411,61 @@ class DiffBackupIntervalInHours(int, Enum, metaclass=CaseInsensitiveEnumMeta): TWELVE = 12 TWENTY_FOUR = 24 + class DnsRefreshConfigurationPropertiesStatus(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The status of the DNS refresh operation. - """ + """The status of the DNS refresh operation.""" SUCCEEDED = "Succeeded" FAILED = "Failed" + +class DtcName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """DtcName.""" + + CURRENT = "current" + + class ElasticPoolLicenseType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The license type to apply for this elastic pool. - """ + """The license type to apply for this elastic pool.""" LICENSE_INCLUDED = "LicenseIncluded" BASE_PRICE = "BasePrice" + class ElasticPoolState(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The state of the elastic pool. - """ + """The state of the elastic pool.""" CREATING = "Creating" READY = "Ready" DISABLED = "Disabled" + class EncryptionProtectorName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """EncryptionProtectorName.""" CURRENT = "current" + class FailoverGroupReplicationRole(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Local replication role of the failover group instance. - """ + """Local replication role of the failover group instance.""" PRIMARY = "Primary" SECONDARY = "Secondary" + class GeoBackupPolicyName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """GeoBackupPolicyName.""" DEFAULT = "Default" + class GeoBackupPolicyState(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The state of the geo backup policy. - """ + """The state of the geo backup policy.""" DISABLED = "Disabled" ENABLED = "Enabled" + class IdentityType(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The identity type. Set this to 'SystemAssigned' in order to automatically create and assign an Azure Active Directory principal for the resource. @@ -439,6 +476,7 @@ class IdentityType(str, Enum, metaclass=CaseInsensitiveEnumMeta): USER_ASSIGNED = "UserAssigned" SYSTEM_ASSIGNED_USER_ASSIGNED = "SystemAssigned,UserAssigned" + class ImplementationMethod(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Gets the method in which this recommended action can be manually implemented. e.g., TSql, AzurePowerShell. @@ -447,13 +485,14 @@ class ImplementationMethod(str, Enum, metaclass=CaseInsensitiveEnumMeta): T_SQL = "TSql" AZURE_POWER_SHELL = "AzurePowerShell" + class InstanceFailoverGroupReplicationRole(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Local replication role of the failover group instance. - """ + """Local replication role of the failover group instance.""" PRIMARY = "Primary" SECONDARY = "Secondary" + class InstancePoolLicenseType(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The license type. Possible values are 'LicenseIncluded' (price for SQL license is included) and 'BasePrice' (without SQL license price). @@ -462,17 +501,18 @@ class InstancePoolLicenseType(str, Enum, metaclass=CaseInsensitiveEnumMeta): LICENSE_INCLUDED = "LicenseIncluded" BASE_PRICE = "BasePrice" + class IsRetryable(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Gets whether the error could be ignored and recommended action could be retried. Possible - values are: Yes/No + values are: Yes/No. """ YES = "Yes" NO = "No" + class JobAgentState(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The state of the job agent. - """ + """The state of the job agent.""" CREATING = "Creating" READY = "Ready" @@ -480,9 +520,9 @@ class JobAgentState(str, Enum, metaclass=CaseInsensitiveEnumMeta): DELETING = "Deleting" DISABLED = "Disabled" + class JobExecutionLifecycle(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The detailed state of the job execution. - """ + """The detailed state of the job execution.""" CREATED = "Created" IN_PROGRESS = "InProgress" @@ -495,41 +535,41 @@ class JobExecutionLifecycle(str, Enum, metaclass=CaseInsensitiveEnumMeta): CANCELED = "Canceled" SKIPPED = "Skipped" + class JobScheduleType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Schedule interval type - """ + """Schedule interval type.""" ONCE = "Once" RECURRING = "Recurring" + class JobStepActionSource(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The source of the action to execute. - """ + """The source of the action to execute.""" INLINE = "Inline" + class JobStepActionType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Type of action being executed by the job step. - """ + """Type of action being executed by the job step.""" T_SQL = "TSql" + class JobStepOutputType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The output destination type. - """ + """The output destination type.""" SQL_DATABASE = "SqlDatabase" + class JobTargetGroupMembershipType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Whether the target is included or excluded from the group. - """ + """Whether the target is included or excluded from the group.""" INCLUDE = "Include" EXCLUDE = "Exclude" + class JobTargetType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The type of the target. - """ + """The type of the target.""" TARGET_GROUP = "TargetGroup" SQL_DATABASE = "SqlDatabase" @@ -537,20 +577,22 @@ class JobTargetType(str, Enum, metaclass=CaseInsensitiveEnumMeta): SQL_SHARD_MAP = "SqlShardMap" SQL_SERVER = "SqlServer" + class LedgerDigestUploadsName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """LedgerDigestUploadsName.""" CURRENT = "current" + class LedgerDigestUploadsState(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Specifies the state of ledger digest upload. - """ + """Specifies the state of ledger digest upload.""" ENABLED = "Enabled" DISABLED = "Disabled" + class LogSizeUnit(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The units that the limit is expressed in. - """ + """The units that the limit is expressed in.""" MEGABYTES = "Megabytes" GIGABYTES = "Gigabytes" @@ -558,10 +600,13 @@ class LogSizeUnit(str, Enum, metaclass=CaseInsensitiveEnumMeta): PETABYTES = "Petabytes" PERCENT = "Percent" + class LongTermRetentionPolicyName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """LongTermRetentionPolicyName.""" DEFAULT = "default" + class ManagedDatabaseCreateMode(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Managed database create mode. PointInTimeRestore: Create a database by restoring a point in time backup of an existing database. SourceDatabaseName, SourceManagedInstanceName and @@ -579,9 +624,9 @@ class ManagedDatabaseCreateMode(str, Enum, metaclass=CaseInsensitiveEnumMeta): RECOVERY = "Recovery" RESTORE_LONG_TERM_RETENTION_BACKUP = "RestoreLongTermRetentionBackup" + class ManagedDatabaseStatus(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Status of the database. - """ + """Status of the database.""" ONLINE = "Online" OFFLINE = "Offline" @@ -591,12 +636,13 @@ class ManagedDatabaseStatus(str, Enum, metaclass=CaseInsensitiveEnumMeta): RESTORING = "Restoring" UPDATING = "Updating" + class ManagedInstanceAdministratorType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Type of the managed instance administrator. - """ + """Type of the managed instance administrator.""" ACTIVE_DIRECTORY = "ActiveDirectory" + class ManagedInstanceLicenseType(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The license type. Possible values are 'LicenseIncluded' (regular price inclusive of a new SQL license) and 'BasePrice' (discounted AHB price for bringing your own SQL licenses). @@ -605,11 +651,15 @@ class ManagedInstanceLicenseType(str, Enum, metaclass=CaseInsensitiveEnumMeta): LICENSE_INCLUDED = "LicenseIncluded" BASE_PRICE = "BasePrice" + class ManagedInstanceLongTermRetentionPolicyName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """ManagedInstanceLongTermRetentionPolicyName.""" DEFAULT = "default" + class ManagedInstancePropertiesProvisioningState(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """ManagedInstancePropertiesProvisioningState.""" CREATING = "Creating" DELETING = "Deleting" @@ -627,19 +677,20 @@ class ManagedInstancePropertiesProvisioningState(str, Enum, metaclass=CaseInsens REGISTERING = "Registering" TIMED_OUT = "TimedOut" + class ManagedInstanceProxyOverride(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Connection type used for connecting to the instance. - """ + """Connection type used for connecting to the instance.""" PROXY = "Proxy" REDIRECT = "Redirect" DEFAULT = "Default" + class ManagedServerCreateMode(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Specifies the mode of database creation. - + Default: Regular instance creation. - + Restore: Creates an instance by restoring a set of backups to specific point in time. RestorePointInTime and SourceManagedInstanceId must be specified. """ @@ -647,13 +698,15 @@ class ManagedServerCreateMode(str, Enum, metaclass=CaseInsensitiveEnumMeta): DEFAULT = "Default" POINT_IN_TIME_RESTORE = "PointInTimeRestore" + class ManagedShortTermRetentionPolicyName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """ManagedShortTermRetentionPolicyName.""" DEFAULT = "default" + class ManagementOperationState(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The operation state. - """ + """The operation state.""" PENDING = "Pending" IN_PROGRESS = "InProgress" @@ -662,16 +715,18 @@ class ManagementOperationState(str, Enum, metaclass=CaseInsensitiveEnumMeta): CANCEL_IN_PROGRESS = "CancelInProgress" CANCELLED = "Cancelled" + class MaxSizeUnit(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The units that the limit is expressed in. - """ + """The units that the limit is expressed in.""" MEGABYTES = "Megabytes" GIGABYTES = "Gigabytes" TERABYTES = "Terabytes" PETABYTES = "Petabytes" + class MetricType(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """MetricType.""" CPU = "cpu" IO = "io" @@ -679,35 +734,42 @@ class MetricType(str, Enum, metaclass=CaseInsensitiveEnumMeta): DURATION = "duration" DTU = "dtu" + +class MoveOperationMode(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """The move operation mode.""" + + MOVE = "Move" + COPY = "Copy" + + class OperationMode(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Operation Mode. - """ + """Operation Mode.""" POLYBASE_IMPORT = "PolybaseImport" + class OperationOrigin(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The intended executor of the operation. - """ + """The intended executor of the operation.""" USER = "user" SYSTEM = "system" + class PauseDelayTimeUnit(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Unit of time that delay is expressed in - """ + """Unit of time that delay is expressed in.""" MINUTES = "Minutes" + class PerformanceLevelUnit(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Unit type used to measure performance level. - """ + """Unit type used to measure performance level.""" DTU = "DTU" V_CORES = "VCores" + class PrimaryAggregationType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The primary aggregation type defining how metric values are displayed. - """ + """The primary aggregation type defining how metric values are displayed.""" NONE = "None" AVERAGE = "Average" @@ -716,17 +778,17 @@ class PrimaryAggregationType(str, Enum, metaclass=CaseInsensitiveEnumMeta): MAXIMUM = "Maximum" TOTAL = "Total" + class PrincipalType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Principal Type of the sever administrator. - """ + """Principal Type of the sever administrator.""" USER = "User" GROUP = "Group" APPLICATION = "Application" + class PrivateEndpointProvisioningState(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """State of the private endpoint connection. - """ + """State of the private endpoint connection.""" APPROVING = "Approving" READY = "Ready" @@ -734,24 +796,24 @@ class PrivateEndpointProvisioningState(str, Enum, metaclass=CaseInsensitiveEnumM FAILED = "Failed" REJECTING = "Rejecting" + class PrivateLinkServiceConnectionStateActionsRequire(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The actions required for private link service connection. - """ + """The actions required for private link service connection.""" NONE = "None" + class PrivateLinkServiceConnectionStateStatus(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The private link service connection status. - """ + """The private link service connection status.""" APPROVED = "Approved" PENDING = "Pending" REJECTED = "Rejected" DISCONNECTED = "Disconnected" + class ProvisioningState(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The ARM provisioning state of the job execution. - """ + """The ARM provisioning state of the job execution.""" CREATED = "Created" IN_PROGRESS = "InProgress" @@ -759,29 +821,30 @@ class ProvisioningState(str, Enum, metaclass=CaseInsensitiveEnumMeta): FAILED = "Failed" CANCELED = "Canceled" + class QueryMetricUnitType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The unit of the metric. - """ + """The unit of the metric.""" PERCENTAGE = "percentage" KB = "KB" MICROSECONDS = "microseconds" COUNT = "count" + class QueryTimeGrainType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Interval type (length). - """ + """Interval type (length).""" PT1_H = "PT1H" P1_D = "P1D" + class ReadOnlyEndpointFailoverPolicy(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Failover policy of the read-only endpoint for the failover group. - """ + """Failover policy of the read-only endpoint for the failover group.""" DISABLED = "Disabled" ENABLED = "Enabled" + class ReadWriteEndpointFailoverPolicy(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Failover policy of the read-write endpoint for the failover group. If failoverPolicy is Automatic then failoverWithDataLossGracePeriodMinutes is required. @@ -790,6 +853,7 @@ class ReadWriteEndpointFailoverPolicy(str, Enum, metaclass=CaseInsensitiveEnumMe MANUAL = "Manual" AUTOMATIC = "Automatic" + class RecommendedActionCurrentState(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Current state the recommended action is in. Some commonly used states are: Active -> recommended action is active and no action has been taken yet. Pending -> recommended @@ -818,36 +882,40 @@ class RecommendedActionCurrentState(str, Enum, metaclass=CaseInsensitiveEnumMeta SUCCESS = "Success" ERROR = "Error" + class RecommendedActionInitiatedBy(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Gets if approval for applying this recommended action was given by user/system. - """ + """Gets if approval for applying this recommended action was given by user/system.""" USER = "User" SYSTEM = "System" + class RecommendedSensitivityLabelUpdateKind(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """RecommendedSensitivityLabelUpdateKind.""" ENABLE = "enable" DISABLE = "disable" + class ReplicationLinkType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Link type (GEO, NAMED). - """ + """Link type (GEO, NAMED, STANDBY).""" GEO = "GEO" NAMED = "NAMED" + STANDBY = "STANDBY" + class ReplicationMode(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The replication mode of a distributed availability group. Parameter will be ignored during link creation. """ - ASYNC_ENUM = "Async" + ASYNC = "Async" SYNC = "Sync" + class ReplicationRole(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Local replication role. - """ + """Local replication role.""" PRIMARY = "Primary" SECONDARY = "Secondary" @@ -855,50 +923,60 @@ class ReplicationRole(str, Enum, metaclass=CaseInsensitiveEnumMeta): SOURCE = "Source" COPY = "Copy" + class ReplicationState(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Replication state (PENDING, SEEDING, CATCHUP, SUSPENDED). - """ + """Replication state (PENDING, SEEDING, CATCHUP, SUSPENDED).""" PENDING = "PENDING" SEEDING = "SEEDING" CATCH_UP = "CATCH_UP" SUSPENDED = "SUSPENDED" + class ReplicaType(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """ReplicaType.""" PRIMARY = "Primary" READABLE_SECONDARY = "ReadableSecondary" + class RestoreDetailsName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """RestoreDetailsName.""" DEFAULT = "Default" + class RestorePointType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The type of restore point - """ + """The type of restore point.""" CONTINUOUS = "CONTINUOUS" DISCRETE = "DISCRETE" + class SampleName(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The name of the sample schema to apply when creating this database. - """ + """The name of the sample schema to apply when creating this database.""" ADVENTURE_WORKS_LT = "AdventureWorksLT" WIDE_WORLD_IMPORTERS_STD = "WideWorldImportersStd" WIDE_WORLD_IMPORTERS_FULL = "WideWorldImportersFull" + class SecondaryType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The secondary type of the database if it is a secondary. Valid values are Geo and Named. + """The secondary type of the database if it is a secondary. Valid values are Geo, Named and + Standby. """ GEO = "Geo" NAMED = "Named" + STANDBY = "Standby" + class SecurityAlertPolicyName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """SecurityAlertPolicyName.""" DEFAULT = "Default" + class SecurityAlertPolicyState(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Specifies the state of the policy, whether it is enabled or disabled or a policy has not been applied yet on the specific database. @@ -908,6 +986,7 @@ class SecurityAlertPolicyState(str, Enum, metaclass=CaseInsensitiveEnumMeta): ENABLED = "Enabled" DISABLED = "Disabled" + class SecurityAlertsPolicyState(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Specifies the state of the policy, whether it is enabled or disabled or a policy has not been applied yet on the specific database. @@ -916,15 +995,17 @@ class SecurityAlertsPolicyState(str, Enum, metaclass=CaseInsensitiveEnumMeta): ENABLED = "Enabled" DISABLED = "Disabled" + class SecurityEventType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The type of the security event. - """ + """The type of the security event.""" UNDEFINED = "Undefined" SQL_INJECTION_VULNERABILITY = "SqlInjectionVulnerability" SQL_INJECTION_EXPLOIT = "SqlInjectionExploit" + class SensitivityLabelRank(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """SensitivityLabelRank.""" NONE = "None" LOW = "Low" @@ -932,55 +1013,63 @@ class SensitivityLabelRank(str, Enum, metaclass=CaseInsensitiveEnumMeta): HIGH = "High" CRITICAL = "Critical" + class SensitivityLabelSource(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """SensitivityLabelSource.""" CURRENT = "current" RECOMMENDED = "recommended" + class SensitivityLabelUpdateKind(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """SensitivityLabelUpdateKind.""" SET = "set" REMOVE = "remove" + class ServerConnectionType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The server connection type. - """ + """The server connection type.""" DEFAULT = "Default" REDIRECT = "Redirect" PROXY = "Proxy" + class ServerKeyType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The encryption protector type like 'ServiceManaged', 'AzureKeyVault'. - """ + """The encryption protector type like 'ServiceManaged', 'AzureKeyVault'.""" SERVICE_MANAGED = "ServiceManaged" AZURE_KEY_VAULT = "AzureKeyVault" + class ServerNetworkAccessFlag(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Whether or not public endpoint access is allowed for this server. Value is optional but if - passed in, must be 'Enabled' or 'Disabled' + passed in, must be 'Enabled' or 'Disabled'. """ ENABLED = "Enabled" DISABLED = "Disabled" + class ServerTrustGroupPropertiesTrustScopesItem(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """ServerTrustGroupPropertiesTrustScopesItem.""" GLOBAL_TRANSACTIONS = "GlobalTransactions" SERVICE_BROKER = "ServiceBroker" + class ServerWorkspaceFeature(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Whether or not existing server has a workspace created and if it allows connection from - workspace + workspace. """ CONNECTED = "Connected" DISCONNECTED = "Disconnected" + class ServiceObjectiveName(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The serviceLevelObjective for SLO usage metric. - """ + """The serviceLevelObjective for SLO usage metric.""" SYSTEM = "System" SYSTEM0 = "System0" @@ -1048,74 +1137,76 @@ class ServiceObjectiveName(str, Enum, metaclass=CaseInsensitiveEnumMeta): DS2000 = "DS2000" ELASTIC_POOL = "ElasticPool" + class ServicePrincipalType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Service principal type. - """ + """Service principal type.""" NONE = "None" SYSTEM_ASSIGNED = "SystemAssigned" + class ShortTermRetentionPolicyName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """ShortTermRetentionPolicyName.""" DEFAULT = "default" + class SqlAgentConfigurationPropertiesState(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The state of Sql Agent. - """ + """The state of Sql Agent.""" ENABLED = "Enabled" DISABLED = "Disabled" + class StorageCapabilityStorageAccountType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The storage account type for the database's backups. - """ + """The storage account type for the database's backups.""" GRS = "GRS" LRS = "LRS" ZRS = "ZRS" + class StorageKeyType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Storage key type. - """ + """Storage key type.""" SHARED_ACCESS_KEY = "SharedAccessKey" STORAGE_ACCESS_KEY = "StorageAccessKey" + class SyncAgentState(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """State of the sync agent. - """ + """State of the sync agent.""" ONLINE = "Online" OFFLINE = "Offline" NEVER_CONNECTED = "NeverConnected" + class SyncConflictResolutionPolicy(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Conflict resolution policy of the sync group. - """ + """Conflict resolution policy of the sync group.""" HUB_WIN = "HubWin" MEMBER_WIN = "MemberWin" + class SyncDirection(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Sync direction of the sync member. - """ + """Sync direction of the sync member.""" BIDIRECTIONAL = "Bidirectional" ONE_WAY_MEMBER_TO_HUB = "OneWayMemberToHub" ONE_WAY_HUB_TO_MEMBER = "OneWayHubToMember" + class SyncGroupLogType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Type of the sync group log. - """ + """Type of the sync group log.""" ALL = "All" ERROR = "Error" WARNING = "Warning" SUCCESS = "Success" + class SyncGroupState(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Sync state of the sync group. - """ + """Sync state of the sync group.""" NOT_READY = "NotReady" ERROR = "Error" @@ -1123,23 +1214,25 @@ class SyncGroupState(str, Enum, metaclass=CaseInsensitiveEnumMeta): PROGRESSING = "Progressing" GOOD = "Good" + class SyncGroupsType(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """SyncGroupsType.""" ALL = "All" ERROR = "Error" WARNING = "Warning" SUCCESS = "Success" + class SyncMemberDbType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Type of the sync agent linked database. - """ + """Type of the sync agent linked database.""" AZURE_SQL_DATABASE = "AzureSqlDatabase" SQL_SERVER_DATABASE = "SqlServerDatabase" + class SyncMemberState(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Sync state of the sync member. - """ + """Sync state of the sync member.""" SYNC_IN_PROGRESS = "SyncInProgress" SYNC_SUCCEEDED = "SyncSucceeded" @@ -1160,28 +1253,30 @@ class SyncMemberState(str, Enum, metaclass=CaseInsensitiveEnumMeta): REPROVISION_FAILED = "ReprovisionFailed" UN_REPROVISIONED = "UnReprovisioned" + class TableTemporalType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The table temporal type. - """ + """The table temporal type.""" NON_TEMPORAL_TABLE = "NonTemporalTable" HISTORY_TABLE = "HistoryTable" SYSTEM_VERSIONED_TEMPORAL_TABLE = "SystemVersionedTemporalTable" + class TransparentDataEncryptionName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """TransparentDataEncryptionName.""" CURRENT = "current" + class TransparentDataEncryptionState(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Specifies the state of the transparent data encryption. - """ + """Specifies the state of the transparent data encryption.""" ENABLED = "Enabled" DISABLED = "Disabled" + class UnitDefinitionType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The unit of the metric. - """ + """The unit of the metric.""" COUNT = "Count" BYTES = "Bytes" @@ -1190,9 +1285,9 @@ class UnitDefinitionType(str, Enum, metaclass=CaseInsensitiveEnumMeta): COUNT_PER_SECOND = "CountPerSecond" BYTES_PER_SECOND = "BytesPerSecond" + class UnitType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The unit of the metric. - """ + """The unit of the metric.""" COUNT = "count" BYTES = "bytes" @@ -1201,7 +1296,9 @@ class UnitType(str, Enum, metaclass=CaseInsensitiveEnumMeta): COUNT_PER_SECOND = "countPerSecond" BYTES_PER_SECOND = "bytesPerSecond" + class UpsertManagedServerOperationStepStatus(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """UpsertManagedServerOperationStepStatus.""" NOT_STARTED = "NotStarted" IN_PROGRESS = "InProgress" @@ -1210,9 +1307,9 @@ class UpsertManagedServerOperationStepStatus(str, Enum, metaclass=CaseInsensitiv FAILED = "Failed" CANCELED = "Canceled" + class VirtualNetworkRuleState(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """Virtual Network Rule State - """ + """Virtual Network Rule State.""" INITIALIZING = "Initializing" IN_PROGRESS = "InProgress" @@ -1221,27 +1318,31 @@ class VirtualNetworkRuleState(str, Enum, metaclass=CaseInsensitiveEnumMeta): DELETING = "Deleting" UNKNOWN = "Unknown" + class VulnerabilityAssessmentName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """VulnerabilityAssessmentName.""" DEFAULT = "default" + class VulnerabilityAssessmentPolicyBaselineName(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """VulnerabilityAssessmentPolicyBaselineName.""" MASTER = "master" DEFAULT = "default" + class VulnerabilityAssessmentScanState(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The scan status. - """ + """The scan status.""" PASSED = "Passed" FAILED = "Failed" FAILED_TO_RUN = "FailedToRun" IN_PROGRESS = "InProgress" + class VulnerabilityAssessmentScanTriggerType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The scan trigger type. - """ + """The scan trigger type.""" ON_DEMAND = "OnDemand" RECURRING = "Recurring" diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/__init__.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/__init__.py index 3848df9ec3ed4..1c28b37b61019 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/__init__.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/__init__.py @@ -24,7 +24,9 @@ from ._database_schemas_operations import DatabaseSchemasOperations from ._database_security_alert_policies_operations import DatabaseSecurityAlertPoliciesOperations from ._database_tables_operations import DatabaseTablesOperations -from ._database_vulnerability_assessment_rule_baselines_operations import DatabaseVulnerabilityAssessmentRuleBaselinesOperations +from ._database_vulnerability_assessment_rule_baselines_operations import ( + DatabaseVulnerabilityAssessmentRuleBaselinesOperations, +) from ._database_vulnerability_assessments_operations import DatabaseVulnerabilityAssessmentsOperations from ._database_vulnerability_assessment_scans_operations import DatabaseVulnerabilityAssessmentScansOperations from ._data_warehouse_user_activities_operations import DataWarehouseUserActivitiesOperations @@ -51,27 +53,37 @@ from ._managed_backup_short_term_retention_policies_operations import ManagedBackupShortTermRetentionPoliciesOperations from ._managed_database_columns_operations import ManagedDatabaseColumnsOperations from ._managed_database_queries_operations import ManagedDatabaseQueriesOperations -from ._managed_database_restore_details_operations import ManagedDatabaseRestoreDetailsOperations -from ._managed_databases_operations import ManagedDatabasesOperations from ._managed_database_schemas_operations import ManagedDatabaseSchemasOperations from ._managed_database_security_alert_policies_operations import ManagedDatabaseSecurityAlertPoliciesOperations from ._managed_database_security_events_operations import ManagedDatabaseSecurityEventsOperations from ._managed_database_tables_operations import ManagedDatabaseTablesOperations from ._managed_database_transparent_data_encryption_operations import ManagedDatabaseTransparentDataEncryptionOperations -from ._managed_database_vulnerability_assessment_rule_baselines_operations import ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations +from ._managed_database_vulnerability_assessment_rule_baselines_operations import ( + ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations, +) from ._managed_database_vulnerability_assessments_operations import ManagedDatabaseVulnerabilityAssessmentsOperations -from ._managed_database_vulnerability_assessment_scans_operations import ManagedDatabaseVulnerabilityAssessmentScansOperations +from ._managed_database_vulnerability_assessment_scans_operations import ( + ManagedDatabaseVulnerabilityAssessmentScansOperations, +) from ._managed_instance_administrators_operations import ManagedInstanceAdministratorsOperations -from ._managed_instance_azure_ad_only_authentications_operations import ManagedInstanceAzureADOnlyAuthenticationsOperations +from ._managed_instance_azure_ad_only_authentications_operations import ( + ManagedInstanceAzureADOnlyAuthenticationsOperations, +) from ._managed_instance_encryption_protectors_operations import ManagedInstanceEncryptionProtectorsOperations from ._managed_instance_keys_operations import ManagedInstanceKeysOperations -from ._managed_instance_long_term_retention_policies_operations import ManagedInstanceLongTermRetentionPoliciesOperations +from ._managed_instance_long_term_retention_policies_operations import ( + ManagedInstanceLongTermRetentionPoliciesOperations, +) from ._managed_instance_operations_operations import ManagedInstanceOperationsOperations -from ._managed_instance_private_endpoint_connections_operations import ManagedInstancePrivateEndpointConnectionsOperations +from ._managed_instance_private_endpoint_connections_operations import ( + ManagedInstancePrivateEndpointConnectionsOperations, +) from ._managed_instance_private_link_resources_operations import ManagedInstancePrivateLinkResourcesOperations from ._managed_instance_tde_certificates_operations import ManagedInstanceTdeCertificatesOperations from ._managed_instance_vulnerability_assessments_operations import ManagedInstanceVulnerabilityAssessmentsOperations -from ._managed_restorable_dropped_database_backup_short_term_retention_policies_operations import ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations +from ._managed_restorable_dropped_database_backup_short_term_retention_policies_operations import ( + ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations, +) from ._managed_server_security_alert_policies_operations import ManagedServerSecurityAlertPoliciesOperations from ._operations import Operations from ._private_endpoint_connections_operations import PrivateEndpointConnectionsOperations @@ -119,9 +131,10 @@ from ._server_trust_certificates_operations import ServerTrustCertificatesOperations from ._ipv6_firewall_rules_operations import IPv6FirewallRulesOperations from ._endpoint_certificates_operations import EndpointCertificatesOperations -from ._replication_links_operations import ReplicationLinksOperations from ._managed_database_sensitivity_labels_operations import ManagedDatabaseSensitivityLabelsOperations -from ._managed_database_recommended_sensitivity_labels_operations import ManagedDatabaseRecommendedSensitivityLabelsOperations +from ._managed_database_recommended_sensitivity_labels_operations import ( + ManagedDatabaseRecommendedSensitivityLabelsOperations, +) from ._sensitivity_labels_operations import SensitivityLabelsOperations from ._recommended_sensitivity_labels_operations import RecommendedSensitivityLabelsOperations from ._server_blob_auditing_policies_operations import ServerBlobAuditingPoliciesOperations @@ -131,136 +144,150 @@ from ._database_advanced_threat_protection_settings_operations import DatabaseAdvancedThreatProtectionSettingsOperations from ._server_advanced_threat_protection_settings_operations import ServerAdvancedThreatProtectionSettingsOperations from ._managed_server_dns_aliases_operations import ManagedServerDnsAliasesOperations +from ._managed_instance_dtcs_operations import ManagedInstanceDtcsOperations +from ._managed_database_advanced_threat_protection_settings_operations import ( + ManagedDatabaseAdvancedThreatProtectionSettingsOperations, +) +from ._managed_instance_advanced_threat_protection_settings_operations import ( + ManagedInstanceAdvancedThreatProtectionSettingsOperations, +) +from ._replication_links_operations import ReplicationLinksOperations +from ._managed_database_restore_details_operations import ManagedDatabaseRestoreDetailsOperations +from ._managed_databases_operations import ManagedDatabasesOperations from ._patch import __all__ as _patch_all from ._patch import * # type: ignore # pylint: disable=unused-wildcard-import from ._patch import patch_sdk as _patch_sdk + __all__ = [ - 'RecoverableDatabasesOperations', - 'DataMaskingPoliciesOperations', - 'DataMaskingRulesOperations', - 'GeoBackupPoliciesOperations', - 'DatabasesOperations', - 'ElasticPoolsOperations', - 'ServerCommunicationLinksOperations', - 'ServiceObjectivesOperations', - 'ElasticPoolActivitiesOperations', - 'ElasticPoolDatabaseActivitiesOperations', - 'ServerUsagesOperations', - 'DatabaseAdvisorsOperations', - 'DatabaseAutomaticTuningOperations', - 'DatabaseColumnsOperations', - 'DatabaseRecommendedActionsOperations', - 'DatabaseSchemasOperations', - 'DatabaseSecurityAlertPoliciesOperations', - 'DatabaseTablesOperations', - 'DatabaseVulnerabilityAssessmentRuleBaselinesOperations', - 'DatabaseVulnerabilityAssessmentsOperations', - 'DatabaseVulnerabilityAssessmentScansOperations', - 'DataWarehouseUserActivitiesOperations', - 'DeletedServersOperations', - 'ElasticPoolOperationsOperations', - 'EncryptionProtectorsOperations', - 'FailoverGroupsOperations', - 'FirewallRulesOperations', - 'InstanceFailoverGroupsOperations', - 'InstancePoolsOperations', - 'JobAgentsOperations', - 'JobCredentialsOperations', - 'JobExecutionsOperations', - 'JobsOperations', - 'JobStepExecutionsOperations', - 'JobStepsOperations', - 'JobTargetExecutionsOperations', - 'JobTargetGroupsOperations', - 'JobVersionsOperations', - 'CapabilitiesOperations', - 'LongTermRetentionPoliciesOperations', - 'MaintenanceWindowOptionsOperations', - 'MaintenanceWindowsOperations', - 'ManagedBackupShortTermRetentionPoliciesOperations', - 'ManagedDatabaseColumnsOperations', - 'ManagedDatabaseQueriesOperations', - 'ManagedDatabaseRestoreDetailsOperations', - 'ManagedDatabasesOperations', - 'ManagedDatabaseSchemasOperations', - 'ManagedDatabaseSecurityAlertPoliciesOperations', - 'ManagedDatabaseSecurityEventsOperations', - 'ManagedDatabaseTablesOperations', - 'ManagedDatabaseTransparentDataEncryptionOperations', - 'ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations', - 'ManagedDatabaseVulnerabilityAssessmentsOperations', - 'ManagedDatabaseVulnerabilityAssessmentScansOperations', - 'ManagedInstanceAdministratorsOperations', - 'ManagedInstanceAzureADOnlyAuthenticationsOperations', - 'ManagedInstanceEncryptionProtectorsOperations', - 'ManagedInstanceKeysOperations', - 'ManagedInstanceLongTermRetentionPoliciesOperations', - 'ManagedInstanceOperationsOperations', - 'ManagedInstancePrivateEndpointConnectionsOperations', - 'ManagedInstancePrivateLinkResourcesOperations', - 'ManagedInstanceTdeCertificatesOperations', - 'ManagedInstanceVulnerabilityAssessmentsOperations', - 'ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations', - 'ManagedServerSecurityAlertPoliciesOperations', - 'Operations', - 'PrivateEndpointConnectionsOperations', - 'PrivateLinkResourcesOperations', - 'RecoverableManagedDatabasesOperations', - 'RestorePointsOperations', - 'ServerAdvisorsOperations', - 'ServerAutomaticTuningOperations', - 'ServerAzureADAdministratorsOperations', - 'ServerAzureADOnlyAuthenticationsOperations', - 'ServerDevOpsAuditSettingsOperations', - 'ServerDnsAliasesOperations', - 'ServerKeysOperations', - 'ServerOperationsOperations', - 'ServerSecurityAlertPoliciesOperations', - 'ServerTrustGroupsOperations', - 'ServerVulnerabilityAssessmentsOperations', - 'SqlAgentOperations', - 'SubscriptionUsagesOperations', - 'SyncAgentsOperations', - 'SyncGroupsOperations', - 'SyncMembersOperations', - 'TdeCertificatesOperations', - 'TimeZonesOperations', - 'VirtualClustersOperations', - 'VirtualNetworkRulesOperations', - 'WorkloadClassifiersOperations', - 'WorkloadGroupsOperations', - 'TransparentDataEncryptionsOperations', - 'BackupShortTermRetentionPoliciesOperations', - 'DatabaseExtensionsOperations', - 'DatabaseOperationsOperations', - 'DatabaseUsagesOperations', - 'LedgerDigestUploadsOperations', - 'OutboundFirewallRulesOperations', - 'ServersOperations', - 'UsagesOperations', - 'LongTermRetentionBackupsOperations', - 'LongTermRetentionManagedInstanceBackupsOperations', - 'ManagedInstancesOperations', - 'RestorableDroppedDatabasesOperations', - 'RestorableDroppedManagedDatabasesOperations', - 'ServerConnectionPoliciesOperations', - 'DistributedAvailabilityGroupsOperations', - 'ServerTrustCertificatesOperations', - 'IPv6FirewallRulesOperations', - 'EndpointCertificatesOperations', - 'ReplicationLinksOperations', - 'ManagedDatabaseSensitivityLabelsOperations', - 'ManagedDatabaseRecommendedSensitivityLabelsOperations', - 'SensitivityLabelsOperations', - 'RecommendedSensitivityLabelsOperations', - 'ServerBlobAuditingPoliciesOperations', - 'DatabaseBlobAuditingPoliciesOperations', - 'ExtendedDatabaseBlobAuditingPoliciesOperations', - 'ExtendedServerBlobAuditingPoliciesOperations', - 'DatabaseAdvancedThreatProtectionSettingsOperations', - 'ServerAdvancedThreatProtectionSettingsOperations', - 'ManagedServerDnsAliasesOperations', + "RecoverableDatabasesOperations", + "DataMaskingPoliciesOperations", + "DataMaskingRulesOperations", + "GeoBackupPoliciesOperations", + "DatabasesOperations", + "ElasticPoolsOperations", + "ServerCommunicationLinksOperations", + "ServiceObjectivesOperations", + "ElasticPoolActivitiesOperations", + "ElasticPoolDatabaseActivitiesOperations", + "ServerUsagesOperations", + "DatabaseAdvisorsOperations", + "DatabaseAutomaticTuningOperations", + "DatabaseColumnsOperations", + "DatabaseRecommendedActionsOperations", + "DatabaseSchemasOperations", + "DatabaseSecurityAlertPoliciesOperations", + "DatabaseTablesOperations", + "DatabaseVulnerabilityAssessmentRuleBaselinesOperations", + "DatabaseVulnerabilityAssessmentsOperations", + "DatabaseVulnerabilityAssessmentScansOperations", + "DataWarehouseUserActivitiesOperations", + "DeletedServersOperations", + "ElasticPoolOperationsOperations", + "EncryptionProtectorsOperations", + "FailoverGroupsOperations", + "FirewallRulesOperations", + "InstanceFailoverGroupsOperations", + "InstancePoolsOperations", + "JobAgentsOperations", + "JobCredentialsOperations", + "JobExecutionsOperations", + "JobsOperations", + "JobStepExecutionsOperations", + "JobStepsOperations", + "JobTargetExecutionsOperations", + "JobTargetGroupsOperations", + "JobVersionsOperations", + "CapabilitiesOperations", + "LongTermRetentionPoliciesOperations", + "MaintenanceWindowOptionsOperations", + "MaintenanceWindowsOperations", + "ManagedBackupShortTermRetentionPoliciesOperations", + "ManagedDatabaseColumnsOperations", + "ManagedDatabaseQueriesOperations", + "ManagedDatabaseSchemasOperations", + "ManagedDatabaseSecurityAlertPoliciesOperations", + "ManagedDatabaseSecurityEventsOperations", + "ManagedDatabaseTablesOperations", + "ManagedDatabaseTransparentDataEncryptionOperations", + "ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations", + "ManagedDatabaseVulnerabilityAssessmentsOperations", + "ManagedDatabaseVulnerabilityAssessmentScansOperations", + "ManagedInstanceAdministratorsOperations", + "ManagedInstanceAzureADOnlyAuthenticationsOperations", + "ManagedInstanceEncryptionProtectorsOperations", + "ManagedInstanceKeysOperations", + "ManagedInstanceLongTermRetentionPoliciesOperations", + "ManagedInstanceOperationsOperations", + "ManagedInstancePrivateEndpointConnectionsOperations", + "ManagedInstancePrivateLinkResourcesOperations", + "ManagedInstanceTdeCertificatesOperations", + "ManagedInstanceVulnerabilityAssessmentsOperations", + "ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations", + "ManagedServerSecurityAlertPoliciesOperations", + "Operations", + "PrivateEndpointConnectionsOperations", + "PrivateLinkResourcesOperations", + "RecoverableManagedDatabasesOperations", + "RestorePointsOperations", + "ServerAdvisorsOperations", + "ServerAutomaticTuningOperations", + "ServerAzureADAdministratorsOperations", + "ServerAzureADOnlyAuthenticationsOperations", + "ServerDevOpsAuditSettingsOperations", + "ServerDnsAliasesOperations", + "ServerKeysOperations", + "ServerOperationsOperations", + "ServerSecurityAlertPoliciesOperations", + "ServerTrustGroupsOperations", + "ServerVulnerabilityAssessmentsOperations", + "SqlAgentOperations", + "SubscriptionUsagesOperations", + "SyncAgentsOperations", + "SyncGroupsOperations", + "SyncMembersOperations", + "TdeCertificatesOperations", + "TimeZonesOperations", + "VirtualClustersOperations", + "VirtualNetworkRulesOperations", + "WorkloadClassifiersOperations", + "WorkloadGroupsOperations", + "TransparentDataEncryptionsOperations", + "BackupShortTermRetentionPoliciesOperations", + "DatabaseExtensionsOperations", + "DatabaseOperationsOperations", + "DatabaseUsagesOperations", + "LedgerDigestUploadsOperations", + "OutboundFirewallRulesOperations", + "ServersOperations", + "UsagesOperations", + "LongTermRetentionBackupsOperations", + "LongTermRetentionManagedInstanceBackupsOperations", + "ManagedInstancesOperations", + "RestorableDroppedDatabasesOperations", + "RestorableDroppedManagedDatabasesOperations", + "ServerConnectionPoliciesOperations", + "DistributedAvailabilityGroupsOperations", + "ServerTrustCertificatesOperations", + "IPv6FirewallRulesOperations", + "EndpointCertificatesOperations", + "ManagedDatabaseSensitivityLabelsOperations", + "ManagedDatabaseRecommendedSensitivityLabelsOperations", + "SensitivityLabelsOperations", + "RecommendedSensitivityLabelsOperations", + "ServerBlobAuditingPoliciesOperations", + "DatabaseBlobAuditingPoliciesOperations", + "ExtendedDatabaseBlobAuditingPoliciesOperations", + "ExtendedServerBlobAuditingPoliciesOperations", + "DatabaseAdvancedThreatProtectionSettingsOperations", + "ServerAdvancedThreatProtectionSettingsOperations", + "ManagedServerDnsAliasesOperations", + "ManagedInstanceDtcsOperations", + "ManagedDatabaseAdvancedThreatProtectionSettingsOperations", + "ManagedInstanceAdvancedThreatProtectionSettingsOperations", + "ReplicationLinksOperations", + "ManagedDatabaseRestoreDetailsOperations", + "ManagedDatabasesOperations", ] __all__.extend([p for p in _patch_all if p not in __all__]) -_patch_sdk() \ No newline at end of file +_patch_sdk() diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_backup_short_term_retention_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_backup_short_term_retention_policies_operations.py index b969ee306da69..009fa65b022d1 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_backup_short_term_retention_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_backup_short_term_retention_policies_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -40,171 +47,146 @@ 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', "2021-02-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "policyName": _SERIALIZER.url("policy_name", policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "policyName": _SERIALIZER.url("policy_name", policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, server_name: str, database_name: str, policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], subscription_id: str, - *, - json: Optional[_models.BackupShortTermRetentionPolicy] = None, - content: Any = None, **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', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "policyName": _SERIALIZER.url("policy_name", policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "policyName": _SERIALIZER.url("policy_name", policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_update_request_initial( +def build_update_request( resource_group_name: str, server_name: str, database_name: str, policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], subscription_id: str, - *, - json: Optional[_models.BackupShortTermRetentionPolicy] = None, - content: Any = None, **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', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "policyName": _SERIALIZER.url("policy_name", policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "policyName": _SERIALIZER.url("policy_name", policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_database_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-02-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class BackupShortTermRetentionPoliciesOperations: """ @@ -225,7 +207,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -238,34 +219,28 @@ def get( """Gets a database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be "default". + :param policy_name: The policy name. Should always be "default". "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ShortTermRetentionPolicyName - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: BackupShortTermRetentionPolicy, or the result of cls(response) + :return: BackupShortTermRetentionPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.BackupShortTermRetentionPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.BackupShortTermRetentionPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.BackupShortTermRetentionPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -273,7 +248,7 @@ def get( policy_name=policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -281,25 +256,23 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('BackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("BackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore def _create_or_update_initial( self, @@ -307,24 +280,28 @@ def _create_or_update_initial( server_name: str, database_name: str, policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], - parameters: _models.BackupShortTermRetentionPolicy, + parameters: Union[_models.BackupShortTermRetentionPolicy, IO], **kwargs: Any ) -> Optional[_models.BackupShortTermRetentionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.BackupShortTermRetentionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.BackupShortTermRetentionPolicy]] - _json = self._serialize.body(parameters, 'BackupShortTermRetentionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "BackupShortTermRetentionPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -333,7 +310,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -341,10 +319,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -353,17 +330,16 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('BackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("BackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, @@ -371,24 +347,109 @@ def begin_create_or_update( database_name: str, policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], parameters: _models.BackupShortTermRetentionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.BackupShortTermRetentionPolicy]: """Updates a database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be "default". + :param policy_name: The policy name. Should always be "default". "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ShortTermRetentionPolicyName - :param parameters: The short term retention policy info. + :param parameters: The short term retention policy info. Required. :type parameters: ~azure.mgmt.sql.models.BackupShortTermRetentionPolicy - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 BackupShortTermRetentionPolicy or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.BackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.BackupShortTermRetentionPolicy]: + """Updates a database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Required. + :type parameters: IO + :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 BackupShortTermRetentionPolicy or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.BackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], + parameters: Union[_models.BackupShortTermRetentionPolicy, IO], + **kwargs: Any + ) -> LROPoller[_models.BackupShortTermRetentionPolicy]: + """Updates a database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.BackupShortTermRetentionPolicy 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 @@ -400,20 +461,17 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either BackupShortTermRetentionPolicy or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.BackupShortTermRetentionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.BackupShortTermRetentionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.BackupShortTermRetentionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -423,39 +481,35 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('BackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("BackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore def _update_initial( self, @@ -463,24 +517,28 @@ def _update_initial( server_name: str, database_name: str, policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], - parameters: _models.BackupShortTermRetentionPolicy, + parameters: Union[_models.BackupShortTermRetentionPolicy, IO], **kwargs: Any ) -> Optional[_models.BackupShortTermRetentionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.BackupShortTermRetentionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.BackupShortTermRetentionPolicy]] - _json = self._serialize.body(parameters, 'BackupShortTermRetentionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "BackupShortTermRetentionPolicy") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -489,7 +547,8 @@ def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -497,10 +556,9 @@ def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -509,17 +567,16 @@ def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('BackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("BackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - @distributed_trace + @overload def begin_update( self, resource_group_name: str, @@ -527,24 +584,109 @@ def begin_update( database_name: str, policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], parameters: _models.BackupShortTermRetentionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.BackupShortTermRetentionPolicy]: """Updates a database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be "default". + :param policy_name: The policy name. Should always be "default". "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ShortTermRetentionPolicyName - :param parameters: The short term retention policy info. + :param parameters: The short term retention policy info. Required. :type parameters: ~azure.mgmt.sql.models.BackupShortTermRetentionPolicy - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 BackupShortTermRetentionPolicy or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.BackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.BackupShortTermRetentionPolicy]: + """Updates a database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Required. + :type parameters: IO + :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 BackupShortTermRetentionPolicy or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.BackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + policy_name: Union[str, "_models.ShortTermRetentionPolicyName"], + parameters: Union[_models.BackupShortTermRetentionPolicy, IO], + **kwargs: Any + ) -> LROPoller[_models.BackupShortTermRetentionPolicy]: + """Updates a database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.BackupShortTermRetentionPolicy 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 @@ -556,20 +698,17 @@ def begin_update( :return: An instance of LROPoller that returns either BackupShortTermRetentionPolicy or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.BackupShortTermRetentionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.BackupShortTermRetentionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.BackupShortTermRetentionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -579,87 +718,74 @@ def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('BackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("BackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.BackupShortTermRetentionPolicyListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.BackupShortTermRetentionPolicy"]: """Gets a database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either BackupShortTermRetentionPolicyListResult or the - result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.BackupShortTermRetentionPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either BackupShortTermRetentionPolicy or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.BackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.BackupShortTermRetentionPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.BackupShortTermRetentionPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -667,17 +793,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -693,10 +809,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -706,8 +820,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupShortTermRetentionPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_capabilities_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_capabilities_operations.py index 2db34607607ae..4afd79cc3bfe8 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_capabilities_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_capabilities_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Optional, TypeVar, Union -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse from azure.core.rest import HttpRequest @@ -19,13 +23,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_location_request( location_name: str, subscription_id: str, @@ -36,33 +43,30 @@ def build_list_by_location_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/capabilities") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/capabilities" + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if include is not None: - _params['include'] = _SERIALIZER.query("include", include, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["include"] = _SERIALIZER.query("include", include, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class CapabilitiesOperations: """ @@ -83,47 +87,39 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_location( - self, - location_name: str, - include: Optional[Union[str, "_models.CapabilityGroup"]] = None, - **kwargs: Any + self, location_name: str, include: Optional[Union[str, "_models.CapabilityGroup"]] = None, **kwargs: Any ) -> _models.LocationCapabilities: """Gets the subscription capabilities available for the specified location. - :param location_name: The location name whose capabilities are retrieved. + :param location_name: The location name whose capabilities are retrieved. Required. :type location_name: str - :param include: If specified, restricts the response to only include the selected item. Default - value is None. + :param include: If specified, restricts the response to only include the selected item. Known + values are: "supportedEditions", "supportedElasticPoolEditions", + "supportedManagedInstanceVersions", "supportedInstancePoolEditions", and + "supportedManagedInstanceEditions". Default value is None. :type include: str or ~azure.mgmt.sql.models.CapabilityGroup - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: LocationCapabilities, or the result of cls(response) + :return: LocationCapabilities or the result of cls(response) :rtype: ~azure.mgmt.sql.models.LocationCapabilities - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LocationCapabilities] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LocationCapabilities] - request = build_list_by_location_request( location_name=location_name, subscription_id=self._config.subscription_id, - api_version=api_version, include=include, - template_url=self.list_by_location.metadata['url'], + api_version=api_version, + template_url=self.list_by_location.metadata["url"], headers=_headers, params=_params, ) @@ -131,22 +127,20 @@ def list_by_location( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('LocationCapabilities', pipeline_response) + deserialized = self._deserialize("LocationCapabilities", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/capabilities"} # type: ignore - + list_by_location.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/capabilities"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_data_masking_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_data_masking_policies_operations.py index 54b44b5915e6b..5ae40ca7d1858 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_data_masking_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_data_masking_policies_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse from azure.core.rest import HttpRequest @@ -19,101 +23,86 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_create_or_update_request( - subscription_id: str, - resource_group_name: str, - server_name: str, - database_name: str, - *, - json: Optional[_models.DataMaskingPolicy] = None, - content: Any = None, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2014-04-01")) # type: str - data_masking_policy_name = kwargs.pop('data_masking_policy_name', "Default") # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + data_masking_policy_name = kwargs.pop("data_masking_policy_name", "Default") # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "dataMaskingPolicyName": _SERIALIZER.url("data_masking_policy_name", data_masking_policy_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "dataMaskingPolicyName": _SERIALIZER.url("data_masking_policy_name", data_masking_policy_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - subscription_id: str, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2014-04-01")) # type: str - data_masking_policy_name = kwargs.pop('data_masking_policy_name', "Default") # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + data_masking_policy_name = kwargs.pop("data_masking_policy_name", "Default") # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "dataMaskingPolicyName": _SERIALIZER.url("data_masking_policy_name", data_masking_policy_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "dataMaskingPolicyName": _SERIALIZER.url("data_masking_policy_name", data_masking_policy_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class DataMaskingPoliciesOperations: """ @@ -134,64 +123,139 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.DataMaskingPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DataMaskingPolicy: """Creates or updates a database data masking policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: Parameters for creating or updating a data masking policy. + :param parameters: Parameters for creating or updating a data masking policy. Required. :type parameters: ~azure.mgmt.sql.models.DataMaskingPolicy - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword data_masking_policy_name: The name of the database for which the data masking rule + applies. Default value is "Default". Note that overriding this default value may result in + unsupported behavior. + :paramtype data_masking_policy_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: DataMaskingPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DataMaskingPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DataMaskingPolicy: + """Creates or updates a database data masking policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters for creating or updating a data masking policy. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str :keyword data_masking_policy_name: The name of the database for which the data masking rule applies. Default value is "Default". Note that overriding this default value may result in unsupported behavior. :paramtype data_masking_policy_name: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DataMaskingPolicy, or the result of cls(response) + :return: DataMaskingPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DataMaskingPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.DataMaskingPolicy, IO], + **kwargs: Any + ) -> _models.DataMaskingPolicy: + """Creates or updates a database data masking policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters for creating or updating a data masking policy. Is either a model + type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.DataMaskingPolicy or IO + :keyword data_masking_policy_name: The name of the database for which the data masking rule + applies. Default value is "Default". Note that overriding this default value may result in + unsupported behavior. + :paramtype data_masking_policy_name: str + :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 + :return: DataMaskingPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DataMaskingPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - data_masking_policy_name = kwargs.pop('data_masking_policy_name', "Default") # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DataMaskingPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + data_masking_policy_name = kwargs.pop("data_masking_policy_name", "Default") # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DataMaskingPolicy] - _json = self._serialize.body(parameters, 'DataMaskingPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DataMaskingPolicy") request = build_create_or_update_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, + subscription_id=self._config.subscription_id, api_version=api_version, data_masking_policy_name=data_masking_policy_name, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -199,76 +263,64 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DataMaskingPolicy', pipeline_response) + deserialized = self._deserialize("DataMaskingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> _models.DataMaskingPolicy: """Gets a database data masking policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword data_masking_policy_name: The name of the database for which the data masking rule applies. Default value is "Default". Note that overriding this default value may result in unsupported behavior. :paramtype data_masking_policy_name: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DataMaskingPolicy, or the result of cls(response) + :return: DataMaskingPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DataMaskingPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - data_masking_policy_name = kwargs.pop('data_masking_policy_name', "Default") # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DataMaskingPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + data_masking_policy_name = kwargs.pop("data_masking_policy_name", "Default") # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DataMaskingPolicy] - request = build_get_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, + subscription_id=self._config.subscription_id, api_version=api_version, data_masking_policy_name=data_masking_policy_name, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -276,22 +328,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DataMaskingPolicy', pipeline_response) + deserialized = self._deserialize("DataMaskingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_data_masking_rules_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_data_masking_rules_operations.py index 1afd1287ffd02..1c21a9d0518c6 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_data_masking_rules_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_data_masking_rules_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,103 +24,92 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_create_or_update_request( - subscription_id: str, resource_group_name: str, server_name: str, database_name: str, data_masking_rule_name: str, - *, - json: Optional[_models.DataMaskingRule] = None, - content: Any = None, + subscription_id: str, **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', "2014-04-01")) # type: str - data_masking_policy_name = kwargs.pop('data_masking_policy_name', "Default") # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + data_masking_policy_name = kwargs.pop("data_masking_policy_name", "Default") # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}/rules/{dataMaskingRuleName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}/rules/{dataMaskingRuleName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "dataMaskingPolicyName": _SERIALIZER.url("data_masking_policy_name", data_masking_policy_name, 'str'), - "dataMaskingRuleName": _SERIALIZER.url("data_masking_rule_name", data_masking_rule_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "dataMaskingPolicyName": _SERIALIZER.url("data_masking_policy_name", data_masking_policy_name, "str"), + "dataMaskingRuleName": _SERIALIZER.url("data_masking_rule_name", data_masking_rule_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_database_request( - subscription_id: str, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2014-04-01")) # type: str - data_masking_policy_name = kwargs.pop('data_masking_policy_name', "Default") # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + data_masking_policy_name = kwargs.pop("data_masking_policy_name", "Default") # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}/rules") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}/rules", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "dataMaskingPolicyName": _SERIALIZER.url("data_masking_policy_name", data_masking_policy_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "dataMaskingPolicyName": _SERIALIZER.url("data_masking_policy_name", data_masking_policy_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class DataMaskingRulesOperations: """ @@ -137,8 +130,7 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, @@ -146,59 +138,143 @@ def create_or_update( database_name: str, data_masking_rule_name: str, parameters: _models.DataMaskingRule, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DataMaskingRule: """Creates or updates a database data masking rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param data_masking_rule_name: The name of the data masking rule. + :param data_masking_rule_name: The name of the data masking rule. Required. :type data_masking_rule_name: str :param parameters: The required parameters for creating or updating a data masking rule. + Required. :type parameters: ~azure.mgmt.sql.models.DataMaskingRule - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword data_masking_policy_name: The name of the database for which the data masking rule + applies. Default value is "Default". Note that overriding this default value may result in + unsupported behavior. + :paramtype data_masking_policy_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: DataMaskingRule or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DataMaskingRule + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + data_masking_rule_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DataMaskingRule: + """Creates or updates a database data masking rule. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param data_masking_rule_name: The name of the data masking rule. Required. + :type data_masking_rule_name: str + :param parameters: The required parameters for creating or updating a data masking rule. + Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword data_masking_policy_name: The name of the database for which the data masking rule + applies. Default value is "Default". Note that overriding this default value may result in + unsupported behavior. + :paramtype data_masking_policy_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: DataMaskingRule or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DataMaskingRule + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + data_masking_rule_name: str, + parameters: Union[_models.DataMaskingRule, IO], + **kwargs: Any + ) -> _models.DataMaskingRule: + """Creates or updates a database data masking rule. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param data_masking_rule_name: The name of the data masking rule. Required. + :type data_masking_rule_name: str + :param parameters: The required parameters for creating or updating a data masking rule. Is + either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.DataMaskingRule or IO :keyword data_masking_policy_name: The name of the database for which the data masking rule applies. Default value is "Default". Note that overriding this default value may result in unsupported behavior. :paramtype data_masking_policy_name: str + :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 - :return: DataMaskingRule, or the result of cls(response) + :return: DataMaskingRule or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DataMaskingRule - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - data_masking_policy_name = kwargs.pop('data_masking_policy_name', "Default") # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DataMaskingRule] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + data_masking_policy_name = kwargs.pop("data_masking_policy_name", "Default") # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DataMaskingRule] - _json = self._serialize.body(parameters, 'DataMaskingRule') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DataMaskingRule") request = build_create_or_update_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, data_masking_rule_name=data_masking_rule_name, + subscription_id=self._config.subscription_id, api_version=api_version, data_masking_policy_name=data_masking_policy_name, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -206,10 +282,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -217,71 +292,61 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('DataMaskingRule', pipeline_response) + deserialized = self._deserialize("DataMaskingRule", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DataMaskingRule', pipeline_response) + deserialized = self._deserialize("DataMaskingRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}/rules/{dataMaskingRuleName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}/rules/{dataMaskingRuleName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.DataMaskingRuleListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.DataMaskingRule"]: """Gets a list of database data masking rules. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword data_masking_policy_name: The name of the database for which the data masking rule applies. Default value is "Default". Note that overriding this default value may result in unsupported behavior. :paramtype data_masking_policy_name: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DataMaskingRuleListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DataMaskingRuleListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DataMaskingRule or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DataMaskingRule] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - data_masking_policy_name = kwargs.pop('data_masking_policy_name', "Default") # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DataMaskingRuleListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + data_masking_policy_name = kwargs.pop("data_masking_policy_name", "Default") # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DataMaskingRuleListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, + subscription_id=self._config.subscription_id, api_version=api_version, data_masking_policy_name=data_masking_policy_name, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -289,18 +354,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - api_version=api_version, - data_masking_policy_name=data_masking_policy_name, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -316,10 +370,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -329,8 +381,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}/rules"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}/rules"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_data_warehouse_user_activities_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_data_warehouse_user_activities_operations.py index e391e4db49633..76f764f694398 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_data_warehouse_user_activities_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_data_warehouse_user_activities_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -38,73 +45,66 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataWarehouseUserActivities/{dataWarehouseUserActivityName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataWarehouseUserActivities/{dataWarehouseUserActivityName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "dataWarehouseUserActivityName": _SERIALIZER.url("data_warehouse_user_activity_name", data_warehouse_user_activity_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "dataWarehouseUserActivityName": _SERIALIZER.url( + "data_warehouse_user_activity_name", data_warehouse_user_activity_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_database_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataWarehouseUserActivities") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataWarehouseUserActivities", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class DataWarehouseUserActivitiesOperations: """ @@ -125,7 +125,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -138,35 +137,30 @@ def get( """Gets the user activities of a data warehouse which includes running and suspended queries. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param data_warehouse_user_activity_name: The activity name of the data warehouse. + :param data_warehouse_user_activity_name: The activity name of the data warehouse. "current" + Required. :type data_warehouse_user_activity_name: str or ~azure.mgmt.sql.models.DataWarehouseUserActivityName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DataWarehouseUserActivities, or the result of cls(response) + :return: DataWarehouseUserActivities or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DataWarehouseUserActivities - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DataWarehouseUserActivities] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DataWarehouseUserActivities] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -174,7 +168,7 @@ def get( data_warehouse_user_activity_name=data_warehouse_user_activity_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -182,73 +176,62 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DataWarehouseUserActivities', pipeline_response) + deserialized = self._deserialize("DataWarehouseUserActivities", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataWarehouseUserActivities/{dataWarehouseUserActivityName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataWarehouseUserActivities/{dataWarehouseUserActivityName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.DataWarehouseUserActivitiesListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.DataWarehouseUserActivities"]: """List the user activities of a data warehouse which includes running and suspended queries. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DataWarehouseUserActivitiesListResult or the - result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DataWarehouseUserActivitiesListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DataWarehouseUserActivities or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DataWarehouseUserActivities] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DataWarehouseUserActivitiesListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DataWarehouseUserActivitiesListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -256,17 +239,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -282,10 +255,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -295,8 +266,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataWarehouseUserActivities"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataWarehouseUserActivities"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_advanced_threat_protection_settings_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_advanced_threat_protection_settings_operations.py index fec8c84512677..d3f8fbf72b4ba 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_advanced_threat_protection_settings_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_advanced_threat_protection_settings_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,50 +24,46 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_database_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -77,34 +77,33 @@ 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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "advancedThreatProtectionName": _SERIALIZER.url("advanced_threat_protection_name", advanced_threat_protection_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "advancedThreatProtectionName": _SERIALIZER.url( + "advanced_threat_protection_name", advanced_threat_protection_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( @@ -113,47 +112,42 @@ def build_create_or_update_request( database_name: str, advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], subscription_id: str, - *, - json: Optional[_models.DatabaseAdvancedThreatProtection] = None, - content: Any = None, **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', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "advancedThreatProtectionName": _SERIALIZER.url("advanced_threat_protection_name", advanced_threat_protection_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "advancedThreatProtectionName": _SERIALIZER.url( + "advanced_threat_protection_name", advanced_threat_protection_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + class DatabaseAdvancedThreatProtectionSettingsOperations: """ @@ -174,54 +168,44 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.DatabaseAdvancedThreatProtectionListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.DatabaseAdvancedThreatProtection"]: """Gets a list of database's Advanced Threat Protection states. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseAdvancedThreatProtectionListResult or the - result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseAdvancedThreatProtectionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseAdvancedThreatProtection or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseAdvancedThreatProtectionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseAdvancedThreatProtectionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -229,17 +213,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -255,10 +229,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -268,11 +240,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings"} # type: ignore @distributed_trace def get( @@ -286,35 +256,30 @@ def get( """Gets a database's Advanced Threat Protection state. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. :type advanced_threat_protection_name: str or ~azure.mgmt.sql.models.AdvancedThreatProtectionName - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseAdvancedThreatProtection, or the result of cls(response) + :return: DatabaseAdvancedThreatProtection or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseAdvancedThreatProtection - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseAdvancedThreatProtection] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseAdvancedThreatProtection] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -322,7 +287,7 @@ def get( advanced_threat_protection_name=advanced_threat_protection_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -330,27 +295,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseAdvancedThreatProtection', pipeline_response) + deserialized = self._deserialize("DatabaseAdvancedThreatProtection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore - - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, @@ -358,43 +321,121 @@ def create_or_update( database_name: str, advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], parameters: _models.DatabaseAdvancedThreatProtection, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DatabaseAdvancedThreatProtection: """Creates or updates a database's Advanced Threat Protection state. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. :type advanced_threat_protection_name: str or ~azure.mgmt.sql.models.AdvancedThreatProtectionName - :param parameters: The database Advanced Threat Protection state. + :param parameters: The database Advanced Threat Protection state. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseAdvancedThreatProtection - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: DatabaseAdvancedThreatProtection, or the result of cls(response) + :return: DatabaseAdvancedThreatProtection or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseAdvancedThreatProtection - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DatabaseAdvancedThreatProtection: + """Creates or updates a database's Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The database Advanced Threat Protection state. Required. + :type parameters: IO + :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: DatabaseAdvancedThreatProtection or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseAdvancedThreatProtection + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: Union[_models.DatabaseAdvancedThreatProtection, IO], + **kwargs: Any + ) -> _models.DatabaseAdvancedThreatProtection: + """Creates or updates a database's Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The database Advanced Threat Protection state. Is either a model type or a + IO type. Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseAdvancedThreatProtection 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 + :return: DatabaseAdvancedThreatProtection or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseAdvancedThreatProtection + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseAdvancedThreatProtection] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseAdvancedThreatProtection] - _json = self._serialize.body(parameters, 'DatabaseAdvancedThreatProtection') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseAdvancedThreatProtection") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -405,7 +446,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -413,10 +455,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -424,15 +465,14 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('DatabaseAdvancedThreatProtection', pipeline_response) + deserialized = self._deserialize("DatabaseAdvancedThreatProtection", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DatabaseAdvancedThreatProtection', pipeline_response) + deserialized = self._deserialize("DatabaseAdvancedThreatProtection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_advisors_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_advisors_operations.py index df3fef0a78af8..df97a7ed396c4 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_advisors_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_advisors_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, List, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, List, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse from azure.core.rest import HttpRequest @@ -19,13 +23,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_database_request( resource_group_name: str, server_name: str, @@ -38,35 +45,32 @@ def build_list_by_database_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if expand is not None: - _params['$expand'] = _SERIALIZER.query("expand", expand, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$expand"] = _SERIALIZER.query("expand", expand, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -80,34 +84,31 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "advisorName": _SERIALIZER.url("advisor_name", advisor_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "advisorName": _SERIALIZER.url("advisor_name", advisor_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_update_request( @@ -116,47 +117,40 @@ def build_update_request( database_name: str, advisor_name: str, subscription_id: str, - *, - json: Optional[_models.Advisor] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "advisorName": _SERIALIZER.url("advisor_name", advisor_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "advisorName": _SERIALIZER.url("advisor_name", advisor_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) + class DatabaseAdvisorsOperations: """ @@ -177,7 +171,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( self, @@ -190,42 +183,36 @@ def list_by_database( """Gets a list of database advisors. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: list of Advisor, or the result of cls(response) + :return: list of Advisor or the result of cls(response) :rtype: list[~azure.mgmt.sql.models.Advisor] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[List[_models.Advisor]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[List[_models.Advisor]] - request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.list_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -233,66 +220,53 @@ def list_by_database( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('[Advisor]', pipeline_response) + deserialized = self._deserialize("[Advisor]", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors"} # type: ignore - + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - advisor_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, advisor_name: str, **kwargs: Any ) -> _models.Advisor: """Gets a database advisor. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param advisor_name: The name of the Database Advisor. + :param advisor_name: The name of the Database Advisor. Required. :type advisor_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Advisor, or the result of cls(response) + :return: Advisor or the result of cls(response) :rtype: ~azure.mgmt.sql.models.Advisor - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.Advisor] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.Advisor] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -300,7 +274,7 @@ def get( advisor_name=advisor_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -308,27 +282,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('Advisor', pipeline_response) + deserialized = self._deserialize("Advisor", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}"} # type: ignore - @distributed_trace + @overload def update( self, resource_group_name: str, @@ -336,42 +308,115 @@ def update( database_name: str, advisor_name: str, parameters: _models.Advisor, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.Advisor: """Updates a database advisor. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param advisor_name: The name of the Database Advisor. + :param advisor_name: The name of the Database Advisor. Required. :type advisor_name: str - :param parameters: The requested advisor resource state. + :param parameters: The requested advisor resource state. Required. :type parameters: ~azure.mgmt.sql.models.Advisor - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: Advisor or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.Advisor + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + advisor_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.Advisor: + """Updates a database advisor. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advisor_name: The name of the Database Advisor. Required. + :type advisor_name: str + :param parameters: The requested advisor resource state. Required. + :type parameters: IO + :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: Advisor, or the result of cls(response) + :return: Advisor or the result of cls(response) :rtype: ~azure.mgmt.sql.models.Advisor - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace + def update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + advisor_name: str, + parameters: Union[_models.Advisor, IO], + **kwargs: Any + ) -> _models.Advisor: + """Updates a database advisor. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advisor_name: The name of the Database Advisor. Required. + :type advisor_name: str + :param parameters: The requested advisor resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.Advisor 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 + :return: Advisor or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.Advisor + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.Advisor] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.Advisor] - _json = self._serialize.body(parameters, 'Advisor') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "Advisor") request = build_update_request( resource_group_name=resource_group_name, @@ -382,7 +427,8 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -390,22 +436,20 @@ def update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('Advisor', pipeline_response) + deserialized = self._deserialize("Advisor", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_automatic_tuning_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_automatic_tuning_operations.py index 95af764116728..8861210846265 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_automatic_tuning_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_automatic_tuning_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse from azure.core.rest import HttpRequest @@ -19,97 +23,82 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/automaticTuning/current") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/automaticTuning/current", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_update_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - *, - json: Optional[_models.DatabaseAutomaticTuning] = None, - content: Any = None, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/automaticTuning/current") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/automaticTuning/current", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) + class DatabaseAutomaticTuningOperations: """ @@ -130,51 +119,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> _models.DatabaseAutomaticTuning: """Gets a database's automatic tuning. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseAutomaticTuning, or the result of cls(response) + :return: DatabaseAutomaticTuning or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseAutomaticTuning - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseAutomaticTuning] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseAutomaticTuning] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -182,67 +160,132 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseAutomaticTuning', pipeline_response) + deserialized = self._deserialize("DatabaseAutomaticTuning", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/automaticTuning/current"} # type: ignore + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/automaticTuning/current"} # type: ignore - - @distributed_trace + @overload def update( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.DatabaseAutomaticTuning, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DatabaseAutomaticTuning: """Update automatic tuning properties for target database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The requested automatic tuning resource state. + :param parameters: The requested automatic tuning resource state. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseAutomaticTuning - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: DatabaseAutomaticTuning or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseAutomaticTuning + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DatabaseAutomaticTuning: + """Update automatic tuning properties for target database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested automatic tuning resource state. Required. + :type parameters: IO + :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: DatabaseAutomaticTuning or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseAutomaticTuning + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.DatabaseAutomaticTuning, IO], + **kwargs: Any + ) -> _models.DatabaseAutomaticTuning: + """Update automatic tuning properties for target database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested automatic tuning resource state. Is either a model type or a + IO type. Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseAutomaticTuning 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 - :return: DatabaseAutomaticTuning, or the result of cls(response) + :return: DatabaseAutomaticTuning or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseAutomaticTuning - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseAutomaticTuning] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseAutomaticTuning] - _json = self._serialize.body(parameters, 'DatabaseAutomaticTuning') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseAutomaticTuning") request = build_update_request( resource_group_name=resource_group_name, @@ -252,7 +295,8 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -260,22 +304,20 @@ def update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseAutomaticTuning', pipeline_response) + deserialized = self._deserialize("DatabaseAutomaticTuning", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/automaticTuning/current"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/automaticTuning/current"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_blob_auditing_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_blob_auditing_policies_operations.py index 76f561bd07e3d..f7c6d4e32ac28 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_blob_auditing_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_blob_auditing_policies_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,140 +24,118 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_database_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings/{blobAuditingPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings/{blobAuditingPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "blobAuditingPolicyName": _SERIALIZER.url("blob_auditing_policy_name", blob_auditing_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "blobAuditingPolicyName": _SERIALIZER.url("blob_auditing_policy_name", blob_auditing_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - *, - json: Optional[_models.DatabaseBlobAuditingPolicy] = None, - content: Any = None, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings/{blobAuditingPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings/{blobAuditingPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "blobAuditingPolicyName": _SERIALIZER.url("blob_auditing_policy_name", blob_auditing_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "blobAuditingPolicyName": _SERIALIZER.url("blob_auditing_policy_name", blob_auditing_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + class DatabaseBlobAuditingPoliciesOperations: """ @@ -174,54 +156,44 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.DatabaseBlobAuditingPolicyListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.DatabaseBlobAuditingPolicy"]: """Lists auditing settings of a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseBlobAuditingPolicyListResult or the result - of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseBlobAuditingPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseBlobAuditingPolicy or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseBlobAuditingPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseBlobAuditingPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseBlobAuditingPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -229,17 +201,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -255,10 +217,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -268,53 +228,41 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> _models.DatabaseBlobAuditingPolicy: """Gets a database's blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is "default". Note that overriding this default value may result in unsupported behavior. :paramtype blob_auditing_policy_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseBlobAuditingPolicy, or the result of cls(response) + :return: DatabaseBlobAuditingPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseBlobAuditingPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseBlobAuditingPolicy] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseBlobAuditingPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -322,7 +270,7 @@ def get( subscription_id=self._config.subscription_id, blob_auditing_policy_name=blob_auditing_policy_name, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -330,71 +278,142 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("DatabaseBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.DatabaseBlobAuditingPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DatabaseBlobAuditingPolicy: """Creates or updates a database's blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The database blob auditing policy. + :param parameters: The database blob auditing policy. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseBlobAuditingPolicy + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is "default". Note that overriding this default value may result in unsupported behavior. :paramtype blob_auditing_policy_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseBlobAuditingPolicy, or the result of cls(response) + :return: DatabaseBlobAuditingPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseBlobAuditingPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DatabaseBlobAuditingPolicy: + """Creates or updates a database's blob auditing policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The database blob auditing policy. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is + "default". Note that overriding this default value may result in unsupported behavior. + :paramtype blob_auditing_policy_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: DatabaseBlobAuditingPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseBlobAuditingPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.DatabaseBlobAuditingPolicy, IO], + **kwargs: Any + ) -> _models.DatabaseBlobAuditingPolicy: + """Creates or updates a database's blob auditing policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The database blob auditing policy. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseBlobAuditingPolicy or IO + :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is + "default". Note that overriding this default value may result in unsupported behavior. + :paramtype blob_auditing_policy_name: str + :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 + :return: DatabaseBlobAuditingPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseBlobAuditingPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseBlobAuditingPolicy] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseBlobAuditingPolicy] - _json = self._serialize.body(parameters, 'DatabaseBlobAuditingPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseBlobAuditingPolicy") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -405,7 +424,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -413,10 +433,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -424,15 +443,14 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('DatabaseBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("DatabaseBlobAuditingPolicy", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DatabaseBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("DatabaseBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_columns_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_columns_operations.py index f43840b943721..f468b5d3c3b21 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_columns_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_columns_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, List, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_database_request( resource_group_name: str, server_name: str, @@ -43,43 +50,40 @@ def build_list_by_database_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/columns") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/columns", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if schema is not None: - _params['schema'] = [_SERIALIZER.query("schema", q, 'str') if q is not None else '' for q in schema] + _params["schema"] = [_SERIALIZER.query("schema", q, "str") if q is not None else "" for q in schema] if table is not None: - _params['table'] = [_SERIALIZER.query("table", q, 'str') if q is not None else '' for q in table] + _params["table"] = [_SERIALIZER.query("table", q, "str") if q is not None else "" for q in table] if column is not None: - _params['column'] = [_SERIALIZER.query("column", q, 'str') if q is not None else '' for q in column] + _params["column"] = [_SERIALIZER.query("column", q, "str") if q is not None else "" for q in column] if order_by is not None: - _params['orderBy'] = [_SERIALIZER.query("order_by", q, 'str') if q is not None else '' for q in order_by] + _params["orderBy"] = [_SERIALIZER.query("order_by", q, "str") if q is not None else "" for q in order_by] if skiptoken is not None: - _params['$skiptoken'] = _SERIALIZER.query("skiptoken", skiptoken, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$skiptoken"] = _SERIALIZER.query("skiptoken", skiptoken, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_table_request( @@ -96,37 +100,34 @@ def build_list_by_table_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "tableName": _SERIALIZER.url("table_name", table_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "tableName": _SERIALIZER.url("table_name", table_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if filter is not None: - _params['$filter'] = _SERIALIZER.query("filter", filter, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$filter"] = _SERIALIZER.query("filter", filter, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -142,36 +143,34 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "tableName": _SERIALIZER.url("table_name", table_name, 'str'), - "columnName": _SERIALIZER.url("column_name", column_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "tableName": _SERIALIZER.url("table_name", table_name, "str"), + "columnName": _SERIALIZER.url("column_name", column_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class DatabaseColumnsOperations: """ @@ -192,7 +191,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( self, @@ -205,61 +203,56 @@ def list_by_database( order_by: Optional[List[str]] = None, skiptoken: Optional[str] = None, **kwargs: Any - ) -> Iterable[_models.DatabaseColumnListResult]: + ) -> Iterable["_models.DatabaseColumn"]: """List database columns. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema: Default value is None. + :param schema: Default value is None. :type schema: list[str] - :param table: Default value is None. + :param table: Default value is None. :type table: list[str] - :param column: Default value is None. + :param column: Default value is None. :type column: list[str] - :param order_by: Default value is None. + :param order_by: Default value is None. :type order_by: list[str] :param skiptoken: An opaque token that identifies a starting point in the collection. Default value is None. :type skiptoken: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseColumnListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseColumnListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseColumn or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseColumn] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseColumnListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseColumnListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, schema=schema, table=table, column=column, order_by=order_by, skiptoken=skiptoken, - template_url=self.list_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -267,22 +260,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - schema=schema, - table=table, - column=column, - order_by=order_by, - skiptoken=skiptoken, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -298,10 +276,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -311,11 +287,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/columns"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/columns"} # type: ignore @distributed_trace def list_by_table( @@ -327,45 +301,40 @@ def list_by_table( table_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable[_models.DatabaseColumnListResult]: + ) -> Iterable["_models.DatabaseColumn"]: """List database columns. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseColumnListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseColumnListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseColumn or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseColumn] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseColumnListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseColumnListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_table_request( resource_group_name=resource_group_name, server_name=server_name, @@ -373,9 +342,9 @@ def prepare_request(next_link=None): schema_name=schema_name, table_name=table_name, subscription_id=self._config.subscription_id, - api_version=api_version, filter=filter, - template_url=self.list_by_table.metadata['url'], + api_version=api_version, + template_url=self.list_by_table.metadata["url"], headers=_headers, params=_params, ) @@ -383,20 +352,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_table_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - schema_name=schema_name, - table_name=table_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -412,10 +368,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -425,11 +379,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_table.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns"} # type: ignore + list_by_table.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns"} # type: ignore @distributed_trace def get( @@ -445,38 +397,32 @@ def get( """Get database column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseColumn, or the result of cls(response) + :return: DatabaseColumn or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseColumn - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseColumn] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseColumn] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -486,7 +432,7 @@ def get( column_name=column_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -494,22 +440,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseColumn', pipeline_response) + deserialized = self._deserialize("DatabaseColumn", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_extensions_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_extensions_operations.py index e503a3cbb8d92..09d4ebb3a7e2d 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_extensions_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_extensions_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -39,116 +46,100 @@ def build_get_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions/{extensionName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions/{extensionName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "extensionName": _SERIALIZER.url("extension_name", extension_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "extensionName": _SERIALIZER.url("extension_name", extension_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, server_name: str, database_name: str, extension_name: str, subscription_id: str, - *, - json: Optional[_models.DatabaseExtensions] = None, - content: Any = None, **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', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions/{extensionName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions/{extensionName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "extensionName": _SERIALIZER.url("extension_name", extension_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "extensionName": _SERIALIZER.url("extension_name", extension_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_database_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-02-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class DatabaseExtensionsOperations: """ @@ -169,47 +160,35 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - extension_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, extension_name: str, **kwargs: Any ) -> None: """Gets a database extension. This will return resource not found as it is not supported. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param extension_name: + :param extension_name: Required. :type extension_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -217,7 +196,7 @@ def get( # pylint: disable=inconsistent-return-statements extension_name=extension_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -225,10 +204,9 @@ def get( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -238,8 +216,7 @@ def get( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions/{extensionName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions/{extensionName}"} # type: ignore def _create_or_update_initial( self, @@ -247,24 +224,28 @@ def _create_or_update_initial( server_name: str, database_name: str, extension_name: str, - parameters: _models.DatabaseExtensions, + parameters: Union[_models.DatabaseExtensions, IO], **kwargs: Any ) -> Optional[_models.ImportExportExtensionsOperationResult]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ImportExportExtensionsOperationResult]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ImportExportExtensionsOperationResult]] - _json = self._serialize.body(parameters, 'DatabaseExtensions') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseExtensions") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -273,7 +254,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -281,10 +263,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -293,17 +274,16 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ImportExportExtensionsOperationResult', pipeline_response) + deserialized = self._deserialize("ImportExportExtensionsOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions/{extensionName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions/{extensionName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, @@ -311,24 +291,69 @@ def begin_create_or_update( database_name: str, extension_name: str, parameters: _models.DatabaseExtensions, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ImportExportExtensionsOperationResult]: """Perform a database extension operation, like polybase import. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param extension_name: + :param extension_name: Required. :type extension_name: str - :param parameters: The database import request parameters. + :param parameters: The database import request parameters. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseExtensions - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ImportExportExtensionsOperationResult or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ImportExportExtensionsOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + extension_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ImportExportExtensionsOperationResult]: + """Perform a database extension operation, like polybase import. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param extension_name: Required. + :type extension_name: str + :param parameters: The database import request parameters. Required. + :type parameters: IO + :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 @@ -341,20 +366,59 @@ def begin_create_or_update( the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ImportExportExtensionsOperationResult] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + extension_name: str, + parameters: Union[_models.DatabaseExtensions, IO], + **kwargs: Any + ) -> LROPoller[_models.ImportExportExtensionsOperationResult]: + """Perform a database extension operation, like polybase import. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param extension_name: Required. + :type extension_name: str + :param parameters: The database import request parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseExtensions 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. + :return: An instance of LROPoller that returns either ImportExportExtensionsOperationResult or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ImportExportExtensionsOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ImportExportExtensionsOperationResult] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ImportExportExtensionsOperationResult] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -364,87 +428,75 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ImportExportExtensionsOperationResult', pipeline_response) + deserialized = self._deserialize("ImportExportExtensionsOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/extensions/{extensionName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions/{extensionName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.ImportExportExtensionsOperationListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.ImportExportExtensionsOperationResult"]: """List database extension. This will return an empty list as it is not supported. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ImportExportExtensionsOperationListResult or the + :return: An iterator like instance of either ImportExportExtensionsOperationResult or the result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ImportExportExtensionsOperationListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ImportExportExtensionsOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ImportExportExtensionsOperationListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ImportExportExtensionsOperationListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -452,17 +504,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -478,10 +520,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -491,8 +531,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extensions"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_operations_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_operations_operations.py index 4adcceb357078..01d6876fbaac0 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_operations_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_operations_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_cancel_request( resource_group_name: str, server_name: str, @@ -37,67 +44,59 @@ def build_cancel_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/operations/{operationId}/cancel") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/operations/{operationId}/cancel", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "operationId": _SERIALIZER.url("operation_id", operation_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "operationId": _SERIALIZER.url("operation_id", operation_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) def build_list_by_database_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-02-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/operations") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/operations", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class DatabaseOperationsOperations: """ @@ -118,47 +117,35 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def cancel( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - operation_id: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, operation_id: str, **kwargs: Any ) -> None: """Cancels the asynchronous operation on the database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param operation_id: The operation identifier. + :param operation_id: The operation identifier. Required. :type operation_id: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_cancel_request( resource_group_name=resource_group_name, server_name=server_name, @@ -166,7 +153,7 @@ def cancel( # pylint: disable=inconsistent-return-statements operation_id=operation_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.cancel.metadata['url'], + template_url=self.cancel.metadata["url"], headers=_headers, params=_params, ) @@ -174,10 +161,9 @@ def cancel( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -187,55 +173,45 @@ def cancel( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - cancel.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/operations/{operationId}/cancel"} # type: ignore - + cancel.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/operations/{operationId}/cancel"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.DatabaseOperationListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.DatabaseOperation"]: """Gets a list of operations performed on the database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseOperationListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseOperationListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseOperation or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseOperation] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseOperationListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseOperationListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -243,17 +219,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -269,10 +235,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -282,8 +246,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/operations"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/operations"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_recommended_actions_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_recommended_actions_operations.py index 2fb0b8c47be89..a875010d6de9a 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_recommended_actions_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_recommended_actions_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, List, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, List, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse from azure.core.rest import HttpRequest @@ -19,13 +23,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_database_advisor_request( resource_group_name: str, server_name: str, @@ -37,34 +44,31 @@ def build_list_by_database_advisor_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "advisorName": _SERIALIZER.url("advisor_name", advisor_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "advisorName": _SERIALIZER.url("advisor_name", advisor_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -79,35 +83,32 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions/{recommendedActionName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions/{recommendedActionName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "advisorName": _SERIALIZER.url("advisor_name", advisor_name, 'str'), - "recommendedActionName": _SERIALIZER.url("recommended_action_name", recommended_action_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "advisorName": _SERIALIZER.url("advisor_name", advisor_name, "str"), + "recommendedActionName": _SERIALIZER.url("recommended_action_name", recommended_action_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_update_request( @@ -117,48 +118,41 @@ def build_update_request( advisor_name: str, recommended_action_name: str, subscription_id: str, - *, - json: Optional[_models.RecommendedAction] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions/{recommendedActionName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions/{recommendedActionName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "advisorName": _SERIALIZER.url("advisor_name", advisor_name, 'str'), - "recommendedActionName": _SERIALIZER.url("recommended_action_name", recommended_action_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "advisorName": _SERIALIZER.url("advisor_name", advisor_name, "str"), + "recommendedActionName": _SERIALIZER.url("recommended_action_name", recommended_action_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) + class DatabaseRecommendedActionsOperations: """ @@ -179,47 +173,35 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database_advisor( - self, - resource_group_name: str, - server_name: str, - database_name: str, - advisor_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, advisor_name: str, **kwargs: Any ) -> List[_models.RecommendedAction]: """Gets list of Database Recommended Actions. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param advisor_name: The name of the Database Advisor. + :param advisor_name: The name of the Database Advisor. Required. :type advisor_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: list of RecommendedAction, or the result of cls(response) + :return: list of RecommendedAction or the result of cls(response) :rtype: list[~azure.mgmt.sql.models.RecommendedAction] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[List[_models.RecommendedAction]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[List[_models.RecommendedAction]] - request = build_list_by_database_advisor_request( resource_group_name=resource_group_name, server_name=server_name, @@ -227,7 +209,7 @@ def list_by_database_advisor( advisor_name=advisor_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database_advisor.metadata['url'], + template_url=self.list_by_database_advisor.metadata["url"], headers=_headers, params=_params, ) @@ -235,25 +217,23 @@ def list_by_database_advisor( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('[RecommendedAction]', pipeline_response) + deserialized = self._deserialize("[RecommendedAction]", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - list_by_database_advisor.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions"} # type: ignore - + list_by_database_advisor.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions"} # type: ignore @distributed_trace def get( @@ -268,36 +248,30 @@ def get( """Gets a database recommended action. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param advisor_name: The name of the Database Advisor. + :param advisor_name: The name of the Database Advisor. Required. :type advisor_name: str - :param recommended_action_name: The name of Database Recommended Action. + :param recommended_action_name: The name of Database Recommended Action. Required. :type recommended_action_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: RecommendedAction, or the result of cls(response) + :return: RecommendedAction or the result of cls(response) :rtype: ~azure.mgmt.sql.models.RecommendedAction - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RecommendedAction] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RecommendedAction] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -306,7 +280,7 @@ def get( recommended_action_name=recommended_action_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -314,27 +288,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('RecommendedAction', pipeline_response) + deserialized = self._deserialize("RecommendedAction", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions/{recommendedActionName}"} # type: ignore + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions/{recommendedActionName}"} # type: ignore - - @distributed_trace + @overload def update( self, resource_group_name: str, @@ -343,44 +315,123 @@ def update( advisor_name: str, recommended_action_name: str, parameters: _models.RecommendedAction, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.RecommendedAction: """Updates a database recommended action. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param advisor_name: The name of the Database Advisor. + :param advisor_name: The name of the Database Advisor. Required. :type advisor_name: str - :param recommended_action_name: The name of Database Recommended Action. + :param recommended_action_name: The name of Database Recommended Action. Required. :type recommended_action_name: str - :param parameters: The requested recommended action resource state. + :param parameters: The requested recommended action resource state. Required. :type parameters: ~azure.mgmt.sql.models.RecommendedAction - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: RecommendedAction, or the result of cls(response) + :return: RecommendedAction or the result of cls(response) :rtype: ~azure.mgmt.sql.models.RecommendedAction - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + def update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + advisor_name: str, + recommended_action_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.RecommendedAction: + """Updates a database recommended action. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advisor_name: The name of the Database Advisor. Required. + :type advisor_name: str + :param recommended_action_name: The name of Database Recommended Action. Required. + :type recommended_action_name: str + :param parameters: The requested recommended action resource state. Required. + :type parameters: IO + :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: RecommendedAction or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.RecommendedAction + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + advisor_name: str, + recommended_action_name: str, + parameters: Union[_models.RecommendedAction, IO], + **kwargs: Any + ) -> _models.RecommendedAction: + """Updates a database recommended action. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advisor_name: The name of the Database Advisor. Required. + :type advisor_name: str + :param recommended_action_name: The name of Database Recommended Action. Required. + :type recommended_action_name: str + :param parameters: The requested recommended action resource state. Is either a model type or a + IO type. Required. + :type parameters: ~azure.mgmt.sql.models.RecommendedAction 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 + :return: RecommendedAction or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.RecommendedAction + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.RecommendedAction] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.RecommendedAction] - _json = self._serialize.body(parameters, 'RecommendedAction') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "RecommendedAction") request = build_update_request( resource_group_name=resource_group_name, @@ -392,7 +443,8 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -400,22 +452,20 @@ def update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('RecommendedAction', pipeline_response) + deserialized = self._deserialize("RecommendedAction", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions/{recommendedActionName}"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions/{recommendedActionName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_schemas_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_schemas_operations.py index 28c4214bd186c..f865a2c276b8d 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_schemas_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_schemas_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_database_request( resource_group_name: str, server_name: str, @@ -39,35 +46,32 @@ def build_list_by_database_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if filter is not None: - _params['$filter'] = _SERIALIZER.query("filter", filter, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$filter"] = _SERIALIZER.query("filter", filter, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -81,34 +85,32 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class DatabaseSchemasOperations: """ @@ -129,7 +131,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( self, @@ -138,49 +139,44 @@ def list_by_database( database_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable[_models.DatabaseSchemaListResult]: + ) -> Iterable["_models.DatabaseSchema"]: """List database schemas. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseSchemaListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseSchemaListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseSchema or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseSchema] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseSchemaListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseSchemaListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, filter=filter, - template_url=self.list_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -188,18 +184,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -215,10 +200,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -228,52 +211,39 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - schema_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, schema_name: str, **kwargs: Any ) -> _models.DatabaseSchema: """Get database schema. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseSchema, or the result of cls(response) + :return: DatabaseSchema or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseSchema - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseSchema] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseSchema] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -281,7 +251,7 @@ def get( schema_name=schema_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -289,22 +259,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseSchema', pipeline_response) + deserialized = self._deserialize("DatabaseSchema", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_security_alert_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_security_alert_policies_operations.py index 4f089634b4fb3..a224370a22c15 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_security_alert_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_security_alert_policies_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -38,34 +45,31 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "securityAlertPolicyName": _SERIALIZER.url("security_alert_policy_name", security_alert_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "securityAlertPolicyName": _SERIALIZER.url("security_alert_policy_name", security_alert_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( @@ -74,86 +78,72 @@ def build_create_or_update_request( database_name: str, security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], subscription_id: str, - *, - json: Optional[_models.DatabaseSecurityAlertPolicy] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "securityAlertPolicyName": _SERIALIZER.url("security_alert_policy_name", security_alert_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "securityAlertPolicyName": _SERIALIZER.url("security_alert_policy_name", security_alert_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_database_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class DatabaseSecurityAlertPoliciesOperations: """ @@ -174,7 +164,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -187,34 +176,29 @@ def get( """Gets a database's security alert policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the security alert policy is defined. + Required. :type database_name: str - :param security_alert_policy_name: The name of the security alert policy. + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseSecurityAlertPolicy, or the result of cls(response) + :return: DatabaseSecurityAlertPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseSecurityAlertPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseSecurityAlertPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseSecurityAlertPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -222,7 +206,7 @@ def get( security_alert_policy_name=security_alert_policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -230,27 +214,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("DatabaseSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, @@ -258,42 +240,118 @@ def create_or_update( database_name: str, security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], parameters: _models.DatabaseSecurityAlertPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DatabaseSecurityAlertPolicy: """Creates or updates a database's security alert policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the security alert policy is defined. + Required. :type database_name: str - :param security_alert_policy_name: The name of the security alert policy. + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName - :param parameters: The database security alert policy. + :param parameters: The database security alert policy. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseSecurityAlertPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: DatabaseSecurityAlertPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseSecurityAlertPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DatabaseSecurityAlertPolicy: + """Creates or updates a database's security alert policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database for which the security alert policy is defined. + Required. + :type database_name: str + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. + :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName + :param parameters: The database security alert policy. Required. + :type parameters: IO + :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: DatabaseSecurityAlertPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseSecurityAlertPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], + parameters: Union[_models.DatabaseSecurityAlertPolicy, IO], + **kwargs: Any + ) -> _models.DatabaseSecurityAlertPolicy: + """Creates or updates a database's security alert policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database for which the security alert policy is defined. + Required. + :type database_name: str + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. + :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName + :param parameters: The database security alert policy. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseSecurityAlertPolicy 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 - :return: DatabaseSecurityAlertPolicy, or the result of cls(response) + :return: DatabaseSecurityAlertPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseSecurityAlertPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseSecurityAlertPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseSecurityAlertPolicy] - _json = self._serialize.body(parameters, 'DatabaseSecurityAlertPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseSecurityAlertPolicy") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -304,7 +362,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -312,10 +371,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -323,65 +381,57 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('DatabaseSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("DatabaseSecurityAlertPolicy", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DatabaseSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("DatabaseSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.DatabaseSecurityAlertListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.DatabaseSecurityAlertPolicy"]: """Gets a list of database's security alert policies. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the security alert policy is defined. + Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseSecurityAlertListResult or the result of + :return: An iterator like instance of either DatabaseSecurityAlertPolicy or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseSecurityAlertListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseSecurityAlertPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseSecurityAlertListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseSecurityAlertListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -389,17 +439,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -415,10 +455,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -428,8 +466,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_tables_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_tables_operations.py index da6cdc5e520b3..e44a828614834 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_tables_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_tables_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_schema_request( resource_group_name: str, server_name: str, @@ -40,36 +47,33 @@ def build_list_by_schema_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if filter is not None: - _params['$filter'] = _SERIALIZER.query("filter", filter, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$filter"] = _SERIALIZER.query("filter", filter, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -84,35 +88,33 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "tableName": _SERIALIZER.url("table_name", table_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "tableName": _SERIALIZER.url("table_name", table_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class DatabaseTablesOperations: """ @@ -133,7 +135,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_schema( self, @@ -143,52 +144,47 @@ def list_by_schema( schema_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable[_models.DatabaseTableListResult]: + ) -> Iterable["_models.DatabaseTable"]: """List database tables. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseTableListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseTableListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseTable or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseTable] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseTableListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseTableListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_schema_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, schema_name=schema_name, subscription_id=self._config.subscription_id, - api_version=api_version, filter=filter, - template_url=self.list_by_schema.metadata['url'], + api_version=api_version, + template_url=self.list_by_schema.metadata["url"], headers=_headers, params=_params, ) @@ -196,19 +192,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_schema_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - schema_name=schema_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -224,10 +208,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -237,11 +219,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_schema.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables"} # type: ignore + list_by_schema.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables"} # type: ignore @distributed_trace def get( @@ -256,36 +236,30 @@ def get( """Get database table. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseTable, or the result of cls(response) + :return: DatabaseTable or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseTable - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseTable] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseTable] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -294,7 +268,7 @@ def get( table_name=table_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -302,22 +276,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseTable', pipeline_response) + deserialized = self._deserialize("DatabaseTable", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_usages_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_usages_operations.py index 8ed0ad4ced0f5..afc95a4194972 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_usages_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_usages_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,50 +24,47 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_database_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-02-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/usages") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/usages", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class DatabaseUsagesOperations: """ @@ -84,53 +85,43 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.DatabaseUsageListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.DatabaseUsage"]: """Gets database usages. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseUsageListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseUsageListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseUsage or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseUsage] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseUsageListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseUsageListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -138,17 +129,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -164,10 +145,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -177,8 +156,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/usages"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/usages"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_vulnerability_assessment_rule_baselines_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_vulnerability_assessment_rule_baselines_operations.py index 9d089dc9f0319..05bfb489880a5 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_vulnerability_assessment_rule_baselines_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_vulnerability_assessment_rule_baselines_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar, Union - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse from azure.core.rest import HttpRequest @@ -19,13 +23,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -39,36 +46,35 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "ruleId": _SERIALIZER.url("rule_id", rule_id, 'str'), - "baselineName": _SERIALIZER.url("baseline_name", baseline_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "ruleId": _SERIALIZER.url("rule_id", rule_id, "str"), + "baselineName": _SERIALIZER.url("baseline_name", baseline_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( @@ -79,49 +85,43 @@ def build_create_or_update_request( rule_id: str, baseline_name: Union[str, "_models.VulnerabilityAssessmentPolicyBaselineName"], subscription_id: str, - *, - json: Optional[_models.DatabaseVulnerabilityAssessmentRuleBaseline] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "ruleId": _SERIALIZER.url("rule_id", rule_id, 'str'), - "baselineName": _SERIALIZER.url("baseline_name", baseline_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "ruleId": _SERIALIZER.url("rule_id", rule_id, "str"), + "baselineName": _SERIALIZER.url("baseline_name", baseline_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_delete_request( @@ -136,30 +136,31 @@ def build_delete_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "ruleId": _SERIALIZER.url("rule_id", rule_id, 'str'), - "baselineName": _SERIALIZER.url("baseline_name", baseline_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "ruleId": _SERIALIZER.url("rule_id", rule_id, "str"), + "baselineName": _SERIALIZER.url("baseline_name", baseline_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) class DatabaseVulnerabilityAssessmentRuleBaselinesOperations: """ @@ -180,7 +181,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -195,40 +195,36 @@ def get( """Gets a database's vulnerability assessment rule baseline. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the vulnerability assessment rule - baseline is defined. + baseline is defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param rule_id: The vulnerability assessment rule ID. + :param rule_id: The vulnerability assessment rule ID. Required. :type rule_id: str :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a - baseline on a database level rule and master for server level rule). + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseVulnerabilityAssessmentRuleBaseline, or the result of cls(response) + :return: DatabaseVulnerabilityAssessmentRuleBaseline or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentRuleBaseline] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentRuleBaseline] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -238,7 +234,7 @@ def get( baseline_name=baseline_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -246,27 +242,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseVulnerabilityAssessmentRuleBaseline', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessmentRuleBaseline", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, @@ -276,48 +270,143 @@ def create_or_update( rule_id: str, baseline_name: Union[str, "_models.VulnerabilityAssessmentPolicyBaselineName"], parameters: _models.DatabaseVulnerabilityAssessmentRuleBaseline, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DatabaseVulnerabilityAssessmentRuleBaseline: """Creates or updates a database's vulnerability assessment rule baseline. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the vulnerability assessment rule - baseline is defined. + baseline is defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param rule_id: The vulnerability assessment rule ID. + :param rule_id: The vulnerability assessment rule ID. Required. :type rule_id: str :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a - baseline on a database level rule and master for server level rule). + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName - :param parameters: The requested rule baseline resource. + :param parameters: The requested rule baseline resource. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: DatabaseVulnerabilityAssessmentRuleBaseline or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + rule_id: str, + baseline_name: Union[str, "_models.VulnerabilityAssessmentPolicyBaselineName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DatabaseVulnerabilityAssessmentRuleBaseline: + """Creates or updates a database's vulnerability assessment rule baseline. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database for which the vulnerability assessment rule + baseline is defined. Required. + :type database_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param rule_id: The vulnerability assessment rule ID. Required. + :type rule_id: str + :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. + :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName + :param parameters: The requested rule baseline resource. Required. + :type parameters: IO + :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: DatabaseVulnerabilityAssessmentRuleBaseline or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + rule_id: str, + baseline_name: Union[str, "_models.VulnerabilityAssessmentPolicyBaselineName"], + parameters: Union[_models.DatabaseVulnerabilityAssessmentRuleBaseline, IO], + **kwargs: Any + ) -> _models.DatabaseVulnerabilityAssessmentRuleBaseline: + """Creates or updates a database's vulnerability assessment rule baseline. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database for which the vulnerability assessment rule + baseline is defined. Required. + :type database_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param rule_id: The vulnerability assessment rule ID. Required. + :type rule_id: str + :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. + :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName + :param parameters: The requested rule baseline resource. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline 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 - :return: DatabaseVulnerabilityAssessmentRuleBaseline, or the result of cls(response) + :return: DatabaseVulnerabilityAssessmentRuleBaseline or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentRuleBaseline] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentRuleBaseline] - _json = self._serialize.body(parameters, 'DatabaseVulnerabilityAssessmentRuleBaseline') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseVulnerabilityAssessmentRuleBaseline") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -330,7 +419,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -338,25 +428,23 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseVulnerabilityAssessmentRuleBaseline', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessmentRuleBaseline", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -372,40 +460,36 @@ def delete( # pylint: disable=inconsistent-return-statements """Removes the database's vulnerability assessment rule baseline. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the vulnerability assessment rule - baseline is defined. + baseline is defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param rule_id: The vulnerability assessment rule ID. + :param rule_id: The vulnerability assessment rule ID. Required. :type rule_id: str :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a - baseline on a database level rule and master for server level rule). + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -415,7 +499,7 @@ def delete( # pylint: disable=inconsistent-return-statements baseline_name=baseline_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -423,10 +507,9 @@ def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -436,5 +519,4 @@ def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_vulnerability_assessment_scans_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_vulnerability_assessment_scans_operations.py index b078d35425457..2a63a17c61a01 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_vulnerability_assessment_scans_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_vulnerability_assessment_scans_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,14 +26,17 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False -def build_initiate_scan_request_initial( + +def build_initiate_scan_request( resource_group_name: str, server_name: str, database_name: str, @@ -40,29 +47,29 @@ def build_initiate_scan_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "scanId": _SERIALIZER.url("scan_id", scan_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "scanId": _SERIALIZER.url("scan_id", scan_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) def build_list_by_database_request( @@ -76,34 +83,33 @@ def build_list_by_database_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -118,35 +124,34 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "scanId": _SERIALIZER.url("scan_id", scan_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "scanId": _SERIALIZER.url("scan_id", scan_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_export_request( @@ -161,35 +166,35 @@ def build_export_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/export") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/export", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "scanId": _SERIALIZER.url("scan_id", scan_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "scanId": _SERIALIZER.url("scan_id", scan_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class DatabaseVulnerabilityAssessmentScansOperations: """ @@ -210,7 +215,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - def _initiate_scan_initial( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, @@ -220,19 +224,16 @@ def _initiate_scan_initial( # pylint: disable=inconsistent-return-statements scan_id: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_initiate_scan_request_initial( + request = build_initiate_scan_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -240,7 +241,7 @@ def _initiate_scan_initial( # pylint: disable=inconsistent-return-statements scan_id=scan_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._initiate_scan_initial.metadata['url'], + template_url=self._initiate_scan_initial.metadata["url"], headers=_headers, params=_params, ) @@ -248,10 +249,9 @@ def _initiate_scan_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -261,11 +261,10 @@ def _initiate_scan_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _initiate_scan_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan"} # type: ignore - + _initiate_scan_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan"} # type: ignore @distributed_trace - def begin_initiate_scan( # pylint: disable=inconsistent-return-statements + def begin_initiate_scan( self, resource_group_name: str, server_name: str, @@ -277,19 +276,17 @@ def begin_initiate_scan( # pylint: disable=inconsistent-return-statements """Executes a Vulnerability Assessment database scan. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param scan_id: The vulnerability assessment scan Id of the scan to retrieve. + :param scan_id: The vulnerability assessment scan Id of the scan to retrieve. Required. :type scan_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -300,19 +297,16 @@ def begin_initiate_scan( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._initiate_scan_initial( # type: ignore resource_group_name=resource_group_name, @@ -321,37 +315,33 @@ def begin_initiate_scan( # pylint: disable=inconsistent-return-statements vulnerability_assessment_name=vulnerability_assessment_name, scan_id=scan_id, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_initiate_scan.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan"} # type: ignore + begin_initiate_scan.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan"} # type: ignore @distributed_trace def list_by_database( @@ -361,41 +351,37 @@ def list_by_database( database_name: str, vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], **kwargs: Any - ) -> Iterable[_models.VulnerabilityAssessmentScanRecordListResult]: + ) -> Iterable["_models.VulnerabilityAssessmentScanRecord"]: """Lists the vulnerability assessment scans of a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VulnerabilityAssessmentScanRecordListResult or the - result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.VulnerabilityAssessmentScanRecordListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either VulnerabilityAssessmentScanRecord or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.VulnerabilityAssessmentScanRecord] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VulnerabilityAssessmentScanRecordListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VulnerabilityAssessmentScanRecordListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, @@ -403,7 +389,7 @@ def prepare_request(next_link=None): vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -411,18 +397,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - vulnerability_assessment_name=vulnerability_assessment_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -438,10 +413,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -451,11 +424,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans"} # type: ignore @distributed_trace def get( @@ -470,36 +441,31 @@ def get( """Gets a vulnerability assessment scan record of a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param scan_id: The vulnerability assessment scan Id of the scan to retrieve. + :param scan_id: The vulnerability assessment scan Id of the scan to retrieve. Required. :type scan_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VulnerabilityAssessmentScanRecord, or the result of cls(response) + :return: VulnerabilityAssessmentScanRecord or the result of cls(response) :rtype: ~azure.mgmt.sql.models.VulnerabilityAssessmentScanRecord - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VulnerabilityAssessmentScanRecord] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VulnerabilityAssessmentScanRecord] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -508,7 +474,7 @@ def get( scan_id=scan_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -516,25 +482,23 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('VulnerabilityAssessmentScanRecord', pipeline_response) + deserialized = self._deserialize("VulnerabilityAssessmentScanRecord", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}"} # type: ignore @distributed_trace def export( @@ -549,36 +513,31 @@ def export( """Convert an existing scan result to a human readable format. If already exists nothing happens. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the scanned database. + :param database_name: The name of the scanned database. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param scan_id: The vulnerability assessment scan Id. + :param scan_id: The vulnerability assessment scan Id. Required. :type scan_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseVulnerabilityAssessmentScansExport, or the result of cls(response) + :return: DatabaseVulnerabilityAssessmentScansExport or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentScansExport - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentScansExport] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentScansExport] - request = build_export_request( resource_group_name=resource_group_name, server_name=server_name, @@ -587,7 +546,7 @@ def export( scan_id=scan_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.export.metadata['url'], + template_url=self.export.metadata["url"], headers=_headers, params=_params, ) @@ -595,10 +554,9 @@ def export( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -606,15 +564,14 @@ def export( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('DatabaseVulnerabilityAssessmentScansExport', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessmentScansExport", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DatabaseVulnerabilityAssessmentScansExport', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessmentScansExport", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - export.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/export"} # type: ignore - + export.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/export"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_vulnerability_assessments_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_vulnerability_assessments_operations.py index 239f546635786..3393c06bfc4a0 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_vulnerability_assessments_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_database_vulnerability_assessments_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -38,34 +45,33 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( @@ -74,47 +80,41 @@ def build_create_or_update_request( database_name: str, vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], subscription_id: str, - *, - json: Optional[_models.DatabaseVulnerabilityAssessment] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_delete_request( @@ -127,67 +127,61 @@ def build_delete_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_database_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class DatabaseVulnerabilityAssessmentsOperations: """ @@ -208,7 +202,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -221,35 +214,30 @@ def get( """Gets the database's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the vulnerability assessment is - defined. + defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseVulnerabilityAssessment, or the result of cls(response) + :return: DatabaseVulnerabilityAssessment or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessment] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessment] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -257,7 +245,7 @@ def get( vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -265,27 +253,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, @@ -293,43 +279,120 @@ def create_or_update( database_name: str, vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], parameters: _models.DatabaseVulnerabilityAssessment, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DatabaseVulnerabilityAssessment: """Creates or updates the database's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the vulnerability assessment is - defined. + defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param parameters: The requested resource. + :param parameters: The requested resource. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: DatabaseVulnerabilityAssessment or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DatabaseVulnerabilityAssessment: + """Creates or updates the database's vulnerability assessment. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database for which the vulnerability assessment is + defined. Required. + :type database_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param parameters: The requested resource. Required. + :type parameters: IO + :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: DatabaseVulnerabilityAssessment or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + parameters: Union[_models.DatabaseVulnerabilityAssessment, IO], + **kwargs: Any + ) -> _models.DatabaseVulnerabilityAssessment: + """Creates or updates the database's vulnerability assessment. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database for which the vulnerability assessment is + defined. Required. + :type database_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param parameters: The requested resource. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment 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 - :return: DatabaseVulnerabilityAssessment, or the result of cls(response) + :return: DatabaseVulnerabilityAssessment or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessment] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessment] - _json = self._serialize.body(parameters, 'DatabaseVulnerabilityAssessment') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseVulnerabilityAssessment") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -340,7 +403,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -348,10 +412,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -359,18 +422,17 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('DatabaseVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessment", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DatabaseVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -384,35 +446,30 @@ def delete( # pylint: disable=inconsistent-return-statements """Removes the database's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the vulnerability assessment is - defined. + defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -420,7 +477,7 @@ def delete( # pylint: disable=inconsistent-return-statements vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -428,10 +485,9 @@ def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -441,57 +497,47 @@ def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.DatabaseVulnerabilityAssessmentListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.DatabaseVulnerabilityAssessment"]: """Lists the vulnerability assessment policies associated with a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database for which the vulnerability assessment policies - are defined. + are defined. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseVulnerabilityAssessmentListResult or the - result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseVulnerabilityAssessment or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -499,17 +545,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -525,10 +561,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -538,8 +572,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_databases_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_databases_operations.py index 98d063270a740..f366ea9d3543e 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_databases_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_databases_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,348 +26,278 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_metrics_request( - subscription_id: str, - resource_group_name: str, - server_name: str, - database_name: str, - *, - filter: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, *, filter: str, **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', "2014-04-01")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metrics") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metrics", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') - _params['$filter'] = _SERIALIZER.query("filter", filter, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + _params["$filter"] = _SERIALIZER.query("filter", filter, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_metric_definitions_request( - subscription_id: str, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2014-04-01")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metricDefinitions") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metricDefinitions", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - *, - skip_token: Optional[str] = None, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, *, skip_token: Optional[str] = None, **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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if skip_token is not None: - _params['$skipToken'] = _SERIALIZER.query("skip_token", skip_token, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$skipToken"] = _SERIALIZER.query("skip_token", skip_token, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - *, - json: Optional[_models.Database] = None, - content: Any = None, - **kwargs: Any +def build_create_or_update_request( + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_request_initial( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any +def build_delete_request( + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) -def build_update_request_initial( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - *, - json: Optional[_models.DatabaseUpdate] = None, - content: Any = None, - **kwargs: Any +def build_update_request( + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) -def build_export_request_initial( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - *, - json: Optional[_models.ExportDatabaseDefinition] = None, - content: Any = None, - **kwargs: Any +def build_export_request( + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/export") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/export", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) -def build_failover_request_initial( +def build_failover_request( resource_group_name: str, server_name: str, database_name: str, @@ -374,306 +308,248 @@ def build_failover_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/failover") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/failover", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if replica_type is not None: - _params['replicaType'] = _SERIALIZER.query("replica_type", replica_type, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["replicaType"] = _SERIALIZER.query("replica_type", replica_type, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) -def build_import_method_request_initial( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - *, - json: Optional[_models.ImportExistingDatabaseDefinition] = None, - content: Any = None, - **kwargs: Any +def build_import_method_request( + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/import") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/import", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) def build_rename_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - *, - json: Optional[_models.ResourceMoveDefinition] = None, - content: Any = None, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/move") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/move", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) -def build_pause_request_initial( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any +def build_pause_request( + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/pause") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/pause", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) -def build_resume_request_initial( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any +def build_resume_request( + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/resume") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/resume", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) -def build_upgrade_data_warehouse_request_initial( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any +def build_upgrade_data_warehouse_request( + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/upgradeDataWarehouse") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/upgradeDataWarehouse", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) def build_list_by_elastic_pool_request( - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, elastic_pool_name: str, subscription_id: str, **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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/databases") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/databases", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_inaccessible_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/inaccessibleDatabases") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/inaccessibleDatabases", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class DatabasesOperations: # pylint: disable=too-many-public-methods """ @@ -694,56 +570,47 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_metrics( - self, - resource_group_name: str, - server_name: str, - database_name: str, - filter: str, - **kwargs: Any - ) -> Iterable[_models.MetricListResult]: + self, resource_group_name: str, server_name: str, database_name: str, filter: str, **kwargs: Any + ) -> Iterable["_models.Metric"]: """Returns database metrics. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param filter: An OData filter expression that describes a subset of metrics to return. + Required. :type filter: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either MetricListResult or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.MetricListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Metric or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.Metric] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.MetricListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.MetricListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_metrics_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, - api_version=api_version, + subscription_id=self._config.subscription_id, filter=filter, - template_url=self.list_metrics.metadata['url'], + api_version=api_version, + template_url=self.list_metrics.metadata["url"], headers=_headers, params=_params, ) @@ -751,18 +618,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_metrics_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -778,10 +634,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -791,58 +645,47 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_metrics.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metrics"} # type: ignore + list_metrics.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metrics"} # type: ignore @distributed_trace def list_metric_definitions( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.MetricDefinitionListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.MetricDefinition"]: """Returns database metric definitions. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either MetricDefinitionListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.MetricDefinitionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either MetricDefinition or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.MetricDefinition] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.MetricDefinitionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.MetricDefinitionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_metric_definitions_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_metric_definitions.metadata['url'], + template_url=self.list_metric_definitions.metadata["url"], headers=_headers, params=_params, ) @@ -850,17 +693,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_metric_definitions_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -876,10 +709,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -889,57 +720,47 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_metric_definitions.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metricDefinitions"} # type: ignore + list_metric_definitions.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metricDefinitions"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - skip_token: Optional[str] = None, - **kwargs: Any - ) -> Iterable[_models.DatabaseListResult]: + self, resource_group_name: str, server_name: str, skip_token: Optional[str] = None, **kwargs: Any + ) -> Iterable["_models.Database"]: """Gets a list of databases. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param skip_token: Default value is None. + :param skip_token: Default value is None. :type skip_token: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseListResult or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Database or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.Database] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, - api_version=api_version, skip_token=skip_token, - template_url=self.list_by_server.metadata['url'], + api_version=api_version, + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -947,17 +768,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - skip_token=skip_token, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -973,10 +784,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -986,56 +795,42 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases"} # type: ignore @distributed_trace - def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> _models.Database: + def get(self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any) -> _models.Database: """Gets a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Database, or the result of cls(response) + :return: Database or the result of cls(response) :rtype: ~azure.mgmt.sql.models.Database - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.Database] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.Database] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -1043,49 +838,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, database_name: str, - parameters: _models.Database, + parameters: Union[_models.Database, IO], **kwargs: Any ) -> Optional[_models.Database]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.Database]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.Database]] - _json = self._serialize.body(parameters, 'Database') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "Database") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -1093,7 +890,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1101,10 +899,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -1113,42 +910,118 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.Database, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.Database]: """Creates a new database or updates an existing database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The requested database resource state. + :param parameters: The requested database resource state. Required. :type parameters: ~azure.mgmt.sql.models.Database - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 Database or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.Database] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.Database]: + """Creates a new database or updates an existing database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested database resource state. Required. + :type parameters: IO + :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 Database or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.Database] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.Database, IO], + **kwargs: Any + ) -> LROPoller[_models.Database]: + """Creates a new database or updates an existing database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested database resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.Database 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 @@ -1159,20 +1032,17 @@ def begin_create_or_update( Retry-After header is present. :return: An instance of LROPoller that returns either Database or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.Database] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.Database] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.Database] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -1181,66 +1051,55 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1248,10 +1107,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -1261,29 +1119,21 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes the database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1294,80 +1144,77 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore def _update_initial( self, resource_group_name: str, server_name: str, database_name: str, - parameters: _models.DatabaseUpdate, + parameters: Union[_models.DatabaseUpdate, IO], **kwargs: Any ) -> Optional[_models.Database]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.Database]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.Database]] - _json = self._serialize.body(parameters, 'DatabaseUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -1375,7 +1222,8 @@ def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1383,10 +1231,9 @@ def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1395,39 +1242,40 @@ def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore - - @distributed_trace + @overload def begin_update( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.DatabaseUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.Database]: """Updates an existing database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The requested database resource state. + :param parameters: The requested database resource state. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseUpdate - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -1438,85 +1286,157 @@ def begin_update( Retry-After header is present. :return: An instance of LROPoller that returns either Database or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.Database] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.Database] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] - if cont_token is None: - raw_result = self._update_initial( # type: ignore - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - parameters=parameters, - api_version=api_version, - content_type=content_type, - cls=lambda x,y,z: x, - headers=_headers, - params=_params, - **kwargs - ) - kwargs.pop('error_map', None) + @overload + def begin_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.Database]: + """Updates an existing database. - def get_long_running_output(pipeline_response): - deserialized = self._deserialize('Database', pipeline_response) + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested database resource state. Required. + :type parameters: IO + :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 Database or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.Database] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.DatabaseUpdate, IO], + **kwargs: Any + ) -> LROPoller[_models.Database]: + """Updates an existing database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested database resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseUpdate 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. + :return: An instance of LROPoller that returns either Database or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.Database] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = case_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: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.Database] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + if cont_token is None: + raw_result = self._update_initial( # type: ignore + resource_group_name=resource_group_name, + server_name=server_name, + database_name=database_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}"} # type: ignore def _export_initial( self, resource_group_name: str, server_name: str, database_name: str, - parameters: _models.ExportDatabaseDefinition, + parameters: Union[_models.ExportDatabaseDefinition, IO], **kwargs: Any ) -> Optional[_models.ImportExportOperationResult]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ImportExportOperationResult]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ImportExportOperationResult]] - _json = self._serialize.body(parameters, 'ExportDatabaseDefinition') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ExportDatabaseDefinition") - request = build_export_request_initial( + request = build_export_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -1524,7 +1444,8 @@ def _export_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._export_initial.metadata['url'], + content=_content, + template_url=self._export_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1532,10 +1453,9 @@ def _export_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1544,39 +1464,40 @@ def _export_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ImportExportOperationResult', pipeline_response) + deserialized = self._deserialize("ImportExportOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _export_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/export"} # type: ignore - + _export_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/export"} # type: ignore - @distributed_trace + @overload def begin_export( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.ExportDatabaseDefinition, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ImportExportOperationResult]: """Exports a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The database export request parameters. + :param parameters: The database export request parameters. Required. :type parameters: ~azure.mgmt.sql.models.ExportDatabaseDefinition - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -1588,20 +1509,94 @@ def begin_export( :return: An instance of LROPoller that returns either ImportExportOperationResult or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_export( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ImportExportOperationResult]: + """Exports a database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The database export request parameters. Required. + :type parameters: IO + :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 ImportExportOperationResult or the result + of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_export( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.ExportDatabaseDefinition, IO], + **kwargs: Any + ) -> LROPoller[_models.ImportExportOperationResult]: + """Exports a database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The database export request parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ExportDatabaseDefinition 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. + :return: An instance of LROPoller that returns either ImportExportOperationResult or the result + of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ImportExportOperationResult] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ImportExportOperationResult] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._export_initial( # type: ignore resource_group_name=resource_group_name, @@ -1610,39 +1605,35 @@ def begin_export( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ImportExportOperationResult', pipeline_response) + deserialized = self._deserialize("ImportExportOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_export.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/export"} # type: ignore + begin_export.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/export"} # type: ignore def _failover_initial( # pylint: disable=inconsistent-return-statements self, @@ -1652,26 +1643,23 @@ def _failover_initial( # pylint: disable=inconsistent-return-statements replica_type: Optional[Union[str, "_models.ReplicaType"]] = None, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_failover_request_initial( + request = build_failover_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, replica_type=replica_type, - template_url=self._failover_initial.metadata['url'], + api_version=api_version, + template_url=self._failover_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1679,10 +1667,9 @@ def _failover_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1692,11 +1679,10 @@ def _failover_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _failover_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/failover"} # type: ignore - + _failover_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/failover"} # type: ignore @distributed_trace - def begin_failover( # pylint: disable=inconsistent-return-statements + def begin_failover( self, resource_group_name: str, server_name: str, @@ -1707,17 +1693,15 @@ def begin_failover( # pylint: disable=inconsistent-return-statements """Failovers a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database to failover. + :param database_name: The name of the database to failover. Required. :type database_name: str - :param replica_type: The type of replica to be failed over. Default value is None. + :param replica_type: The type of replica to be failed over. Known values are: "Primary" and + "ReadableSecondary". Default value is None. :type replica_type: str or ~azure.mgmt.sql.models.ReplicaType - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1728,19 +1712,16 @@ def begin_failover( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._failover_initial( # type: ignore resource_group_name=resource_group_name, @@ -1748,61 +1729,61 @@ def begin_failover( # pylint: disable=inconsistent-return-statements database_name=database_name, replica_type=replica_type, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_failover.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/failover"} # type: ignore + begin_failover.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/failover"} # type: ignore def _import_method_initial( self, resource_group_name: str, server_name: str, database_name: str, - parameters: _models.ImportExistingDatabaseDefinition, + parameters: Union[_models.ImportExistingDatabaseDefinition, IO], **kwargs: Any ) -> Optional[_models.ImportExportOperationResult]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ImportExportOperationResult]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ImportExportOperationResult]] - _json = self._serialize.body(parameters, 'ImportExistingDatabaseDefinition') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ImportExistingDatabaseDefinition") - request = build_import_method_request_initial( + request = build_import_method_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -1810,7 +1791,8 @@ def _import_method_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._import_method_initial.metadata['url'], + content=_content, + template_url=self._import_method_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1818,10 +1800,9 @@ def _import_method_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1830,39 +1811,40 @@ def _import_method_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ImportExportOperationResult', pipeline_response) + deserialized = self._deserialize("ImportExportOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _import_method_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/import"} # type: ignore + _import_method_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/import"} # type: ignore - - @distributed_trace + @overload def begin_import_method( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.ImportExistingDatabaseDefinition, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ImportExportOperationResult]: """Imports a bacpac into a new database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The database import request parameters. + :param parameters: The database import request parameters. Required. :type parameters: ~azure.mgmt.sql.models.ImportExistingDatabaseDefinition - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -1874,20 +1856,94 @@ def begin_import_method( :return: An instance of LROPoller that returns either ImportExportOperationResult or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_import_method( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ImportExportOperationResult]: + """Imports a bacpac into a new database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The database import request parameters. Required. + :type parameters: IO + :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 ImportExportOperationResult or the result + of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_import_method( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.ImportExistingDatabaseDefinition, IO], + **kwargs: Any + ) -> LROPoller[_models.ImportExportOperationResult]: + """Imports a bacpac into a new database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The database import request parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ImportExistingDatabaseDefinition 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. + :return: An instance of LROPoller that returns either ImportExportOperationResult or the result + of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ImportExportOperationResult] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ImportExportOperationResult] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._import_method_initial( # type: ignore resource_group_name=resource_group_name, @@ -1896,81 +1952,144 @@ def begin_import_method( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ImportExportOperationResult', pipeline_response) + deserialized = self._deserialize("ImportExportOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_import_method.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/import"} # type: ignore + begin_import_method.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/import"} # type: ignore - @distributed_trace + @overload def rename( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.ResourceMoveDefinition, + *, + content_type: str = "application/json", **kwargs: Any ) -> None: """Renames a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database to rename. + :param database_name: The name of the database to rename. Required. :type database_name: str - :param parameters: The resource move definition for renaming this database. + :param parameters: The resource move definition for renaming this database. Required. :type parameters: ~azure.mgmt.sql.models.ResourceMoveDefinition - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def rename( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> None: + """Renames a database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database to rename. Required. + :type database_name: str + :param parameters: The resource move definition for renaming this database. Required. + :type parameters: IO + :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: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def rename( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.ResourceMoveDefinition, IO], + **kwargs: Any + ) -> None: + """Renames a database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database to rename. Required. + :type database_name: str + :param parameters: The resource move definition for renaming this database. Is either a model + type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ResourceMoveDefinition 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 - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'ResourceMoveDefinition') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ResourceMoveDefinition") request = build_rename_request( resource_group_name=resource_group_name, @@ -1980,7 +2099,8 @@ def rename( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self.rename.metadata['url'], + content=_content, + template_url=self.rename.metadata["url"], headers=_headers, params=_params, ) @@ -1988,10 +2108,9 @@ def rename( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -2001,35 +2120,27 @@ def rename( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - rename.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/move"} # type: ignore - + rename.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/move"} # type: ignore def _pause_initial( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> Optional[_models.Database]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.Database]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.Database]] - - request = build_pause_request_initial( + request = build_pause_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._pause_initial.metadata['url'], + template_url=self._pause_initial.metadata["url"], headers=_headers, params=_params, ) @@ -2037,10 +2148,9 @@ def _pause_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -2049,36 +2159,28 @@ def _pause_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _pause_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/pause"} # type: ignore - + _pause_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/pause"} # type: ignore @distributed_trace def begin_pause( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> LROPoller[_models.Database]: """Pauses a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database to be paused. + :param database_name: The name of the database to be paused. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -2089,85 +2191,71 @@ def begin_pause( Retry-After header is present. :return: An instance of LROPoller that returns either Database or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.Database] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.Database] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.Database] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._pause_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_pause.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/pause"} # type: ignore + begin_pause.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/pause"} # type: ignore def _resume_initial( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> Optional[_models.Database]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.Database]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.Database]] - - request = build_resume_request_initial( + request = build_resume_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._resume_initial.metadata['url'], + template_url=self._resume_initial.metadata["url"], headers=_headers, params=_params, ) @@ -2175,10 +2263,9 @@ def _resume_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -2187,36 +2274,28 @@ def _resume_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _resume_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/resume"} # type: ignore - + _resume_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/resume"} # type: ignore @distributed_trace def begin_resume( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> LROPoller[_models.Database]: """Resumes a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database to be resumed. + :param database_name: The name of the database to be resumed. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -2227,85 +2306,71 @@ def begin_resume( Retry-After header is present. :return: An instance of LROPoller that returns either Database or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.Database] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.Database] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.Database] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._resume_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('Database', pipeline_response) + deserialized = self._deserialize("Database", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_resume.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/resume"} # type: ignore + begin_resume.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/resume"} # type: ignore def _upgrade_data_warehouse_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_upgrade_data_warehouse_request_initial( + request = build_upgrade_data_warehouse_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._upgrade_data_warehouse_initial.metadata['url'], + template_url=self._upgrade_data_warehouse_initial.metadata["url"], headers=_headers, params=_params, ) @@ -2313,10 +2378,9 @@ def _upgrade_data_warehouse_initial( # pylint: disable=inconsistent-return-stat request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -2326,29 +2390,21 @@ def _upgrade_data_warehouse_initial( # pylint: disable=inconsistent-return-stat if cls: return cls(pipeline_response, None, {}) - _upgrade_data_warehouse_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/upgradeDataWarehouse"} # type: ignore - + _upgrade_data_warehouse_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/upgradeDataWarehouse"} # type: ignore @distributed_trace - def begin_upgrade_data_warehouse( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + def begin_upgrade_data_warehouse( + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> LROPoller[None]: """Upgrades a data warehouse. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database to be upgraded. + :param database_name: The name of the database to be upgraded. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -2359,102 +2415,87 @@ def begin_upgrade_data_warehouse( # pylint: disable=inconsistent-return-stateme 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._upgrade_data_warehouse_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_upgrade_data_warehouse.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/upgradeDataWarehouse"} # type: ignore + begin_upgrade_data_warehouse.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/upgradeDataWarehouse"} # type: ignore @distributed_trace def list_by_elastic_pool( - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any - ) -> Iterable[_models.DatabaseListResult]: + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any + ) -> Iterable["_models.Database"]: """Gets a list of databases in an elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool. + :param elastic_pool_name: The name of the elastic pool. Required. :type elastic_pool_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseListResult or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Database or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.Database] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_elastic_pool_request( resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_elastic_pool.metadata['url'], + template_url=self.list_by_elastic_pool.metadata["url"], headers=_headers, params=_params, ) @@ -2462,17 +2503,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_elastic_pool_request( - resource_group_name=resource_group_name, - server_name=server_name, - elastic_pool_name=elastic_pool_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -2488,10 +2519,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -2501,53 +2530,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_elastic_pool.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/databases"} # type: ignore + list_by_elastic_pool.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/databases"} # type: ignore @distributed_trace def list_inaccessible_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.DatabaseListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.Database"]: """Gets a list of inaccessible databases in a logical server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseListResult or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Database or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.Database] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_inaccessible_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_inaccessible_by_server.metadata['url'], + template_url=self.list_inaccessible_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -2555,16 +2575,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_inaccessible_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -2580,10 +2591,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -2593,8 +2602,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_inaccessible_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/inaccessibleDatabases"} # type: ignore + list_inaccessible_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/inaccessibleDatabases"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_deleted_servers_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_deleted_servers_operations.py index d88f6254a8540..865749a38149d 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_deleted_servers_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_deleted_servers_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,153 +26,127 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False -def build_list_request( - subscription_id: str, - **kwargs: Any -) -> HttpRequest: + +def build_list_request(subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/deletedServers") path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_get_request( - location_name: str, - deleted_server_name: str, - subscription_id: str, - **kwargs: Any -) -> HttpRequest: + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_get_request(location_name: str, deleted_server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers/{deletedServerName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers/{deletedServerName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "deletedServerName": _SERIALIZER.url("deleted_server_name", deleted_server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "deletedServerName": _SERIALIZER.url("deleted_server_name", deleted_server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_list_by_location_request( - location_name: str, - subscription_id: str, - **kwargs: Any -) -> HttpRequest: +def build_list_by_location_request(location_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_recover_request_initial( - location_name: str, - deleted_server_name: str, - subscription_id: str, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_recover_request( + location_name: str, deleted_server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers/{deletedServerName}/recover") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers/{deletedServerName}/recover", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "deletedServerName": _SERIALIZER.url("deleted_server_name", deleted_server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "deletedServerName": _SERIALIZER.url("deleted_server_name", deleted_server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class DeletedServersOperations: """ @@ -189,40 +167,31 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace - def list( - self, - **kwargs: Any - ) -> Iterable[_models.DeletedServerListResult]: + def list(self, **kwargs: Any) -> Iterable["_models.DeletedServer"]: """Gets a list of all deleted servers in a subscription. - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DeletedServerListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DeletedServerListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DeletedServer or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DeletedServer] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DeletedServerListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DeletedServerListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_request( subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list.metadata['url'], + template_url=self.list.metadata["url"], headers=_headers, params=_params, ) @@ -230,14 +199,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_request( - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -253,10 +215,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -266,51 +226,38 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/deletedServers"} # type: ignore + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/deletedServers"} # type: ignore @distributed_trace - def get( - self, - location_name: str, - deleted_server_name: str, - **kwargs: Any - ) -> _models.DeletedServer: + def get(self, location_name: str, deleted_server_name: str, **kwargs: Any) -> _models.DeletedServer: """Gets a deleted server. - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param deleted_server_name: The name of the deleted server. + :param deleted_server_name: The name of the deleted server. Required. :type deleted_server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DeletedServer, or the result of cls(response) + :return: DeletedServer or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DeletedServer - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DeletedServer] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DeletedServer] - request = build_get_request( location_name=location_name, deleted_server_name=deleted_server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -318,63 +265,52 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DeletedServer', pipeline_response) + deserialized = self._deserialize("DeletedServer", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers/{deletedServerName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers/{deletedServerName}"} # type: ignore @distributed_trace - def list_by_location( - self, - location_name: str, - **kwargs: Any - ) -> Iterable[_models.DeletedServerListResult]: + def list_by_location(self, location_name: str, **kwargs: Any) -> Iterable["_models.DeletedServer"]: """Gets a list of deleted servers for a location. - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DeletedServerListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DeletedServerListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DeletedServer or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DeletedServer] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DeletedServerListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DeletedServerListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_location_request( location_name=location_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_location.metadata['url'], + template_url=self.list_by_location.metadata["url"], headers=_headers, params=_params, ) @@ -382,15 +318,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_location_request( - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -406,10 +334,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -419,36 +345,28 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers"} # type: ignore + list_by_location.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers"} # type: ignore def _recover_initial( - self, - location_name: str, - deleted_server_name: str, - **kwargs: Any + self, location_name: str, deleted_server_name: str, **kwargs: Any ) -> Optional[_models.DeletedServer]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.DeletedServer]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.DeletedServer]] - - request = build_recover_request_initial( + request = build_recover_request( location_name=location_name, deleted_server_name=deleted_server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._recover_initial.metadata['url'], + template_url=self._recover_initial.metadata["url"], headers=_headers, params=_params, ) @@ -456,10 +374,9 @@ def _recover_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -468,32 +385,25 @@ def _recover_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('DeletedServer', pipeline_response) + deserialized = self._deserialize("DeletedServer", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _recover_initial.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers/{deletedServerName}/recover"} # type: ignore - + _recover_initial.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers/{deletedServerName}/recover"} # type: ignore @distributed_trace def begin_recover( - self, - location_name: str, - deleted_server_name: str, - **kwargs: Any + self, location_name: str, deleted_server_name: str, **kwargs: Any ) -> LROPoller[_models.DeletedServer]: """Recovers a deleted server. - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param deleted_server_name: The name of the deleted server. + :param deleted_server_name: The name of the deleted server. Required. :type deleted_server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -505,54 +415,47 @@ def begin_recover( :return: An instance of LROPoller that returns either DeletedServer or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.DeletedServer] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DeletedServer] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DeletedServer] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._recover_initial( # type: ignore location_name=location_name, deleted_server_name=deleted_server_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('DeletedServer', pipeline_response) + deserialized = self._deserialize("DeletedServer", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_recover.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers/{deletedServerName}/recover"} # type: ignore + begin_recover.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/deletedServers/{deletedServerName}/recover"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_distributed_availability_groups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_distributed_availability_groups_operations.py index b488241f5412b..e6c30ebe7a949 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_distributed_availability_groups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_distributed_availability_groups_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,48 +26,45 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_instance_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -76,83 +77,76 @@ 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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "distributedAvailabilityGroupName": _SERIALIZER.url("distributed_availability_group_name", distributed_availability_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "distributedAvailabilityGroupName": _SERIALIZER.url( + "distributed_availability_group_name", distributed_availability_group_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, managed_instance_name: str, distributed_availability_group_name: str, subscription_id: str, - *, - json: Optional[_models.DistributedAvailabilityGroup] = None, - content: Any = None, **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', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "distributedAvailabilityGroupName": _SERIALIZER.url("distributed_availability_group_name", distributed_availability_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "distributedAvailabilityGroupName": _SERIALIZER.url( + "distributed_availability_group_name", distributed_availability_group_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_request_initial( +def build_delete_request( resource_group_name: str, managed_instance_name: str, distributed_availability_group_name: str, @@ -161,74 +155,69 @@ def build_delete_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "distributedAvailabilityGroupName": _SERIALIZER.url("distributed_availability_group_name", distributed_availability_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "distributedAvailabilityGroupName": _SERIALIZER.url( + "distributed_availability_group_name", distributed_availability_group_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) -def build_update_request_initial( +def build_update_request( resource_group_name: str, managed_instance_name: str, distributed_availability_group_name: str, subscription_id: str, - *, - json: Optional[_models.DistributedAvailabilityGroup] = None, - content: Any = None, **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', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "distributedAvailabilityGroupName": _SERIALIZER.url("distributed_availability_group_name", distributed_availability_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "distributedAvailabilityGroupName": _SERIALIZER.url( + "distributed_availability_group_name", distributed_availability_group_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) + class DistributedAvailabilityGroupsOperations: """ @@ -249,50 +238,41 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> Iterable[_models.DistributedAvailabilityGroupsListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.DistributedAvailabilityGroup"]: """Gets a list of a distributed availability groups in instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DistributedAvailabilityGroupsListResult or the - result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DistributedAvailabilityGroupsListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DistributedAvailabilityGroup or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DistributedAvailabilityGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DistributedAvailabilityGroupsListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DistributedAvailabilityGroupsListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -300,16 +280,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -325,10 +296,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -338,11 +307,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups"} # type: ignore @distributed_trace def get( @@ -355,39 +322,33 @@ def get( """Gets a distributed availability group info. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param distributed_availability_group_name: The distributed availability group name. + :param distributed_availability_group_name: The distributed availability group name. Required. :type distributed_availability_group_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DistributedAvailabilityGroup, or the result of cls(response) + :return: DistributedAvailabilityGroup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DistributedAvailabilityGroup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DistributedAvailabilityGroup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DistributedAvailabilityGroup] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, distributed_availability_group_name=distributed_availability_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -395,49 +356,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DistributedAvailabilityGroup', pipeline_response) + deserialized = self._deserialize("DistributedAvailabilityGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, distributed_availability_group_name: str, - parameters: _models.DistributedAvailabilityGroup, + parameters: Union[_models.DistributedAvailabilityGroup, IO], **kwargs: Any ) -> Optional[_models.DistributedAvailabilityGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.DistributedAvailabilityGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.DistributedAvailabilityGroup]] - _json = self._serialize.body(parameters, 'DistributedAvailabilityGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DistributedAvailabilityGroup") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, distributed_availability_group_name=distributed_availability_group_name, @@ -445,7 +408,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -453,10 +417,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -465,42 +428,120 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('DistributedAvailabilityGroup', pipeline_response) + deserialized = self._deserialize("DistributedAvailabilityGroup", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DistributedAvailabilityGroup', pipeline_response) + deserialized = self._deserialize("DistributedAvailabilityGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, distributed_availability_group_name: str, parameters: _models.DistributedAvailabilityGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.DistributedAvailabilityGroup]: """Creates a distributed availability group between Sql On-Prem and Sql Managed Instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param distributed_availability_group_name: The distributed availability group name. + :param distributed_availability_group_name: The distributed availability group name. Required. :type distributed_availability_group_name: str - :param parameters: The distributed availability group info. + :param parameters: The distributed availability group info. Required. :type parameters: ~azure.mgmt.sql.models.DistributedAvailabilityGroup - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 DistributedAvailabilityGroup or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.DistributedAvailabilityGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + distributed_availability_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.DistributedAvailabilityGroup]: + """Creates a distributed availability group between Sql On-Prem and Sql Managed Instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param distributed_availability_group_name: The distributed availability group name. Required. + :type distributed_availability_group_name: str + :param parameters: The distributed availability group info. Required. + :type parameters: IO + :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 DistributedAvailabilityGroup or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.DistributedAvailabilityGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + distributed_availability_group_name: str, + parameters: Union[_models.DistributedAvailabilityGroup, IO], + **kwargs: Any + ) -> LROPoller[_models.DistributedAvailabilityGroup]: + """Creates a distributed availability group between Sql On-Prem and Sql Managed Instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param distributed_availability_group_name: The distributed availability group name. Required. + :type distributed_availability_group_name: str + :param parameters: The distributed availability group info. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.DistributedAvailabilityGroup 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 @@ -512,20 +553,17 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either DistributedAvailabilityGroup or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.DistributedAvailabilityGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DistributedAvailabilityGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DistributedAvailabilityGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -534,39 +572,35 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('DistributedAvailabilityGroup', pipeline_response) + deserialized = self._deserialize("DistributedAvailabilityGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements self, @@ -575,25 +609,22 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements distributed_availability_group_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, distributed_availability_group_name=distributed_availability_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -601,10 +632,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -614,11 +644,10 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements + def begin_delete( self, resource_group_name: str, managed_instance_name: str, @@ -628,15 +657,12 @@ def begin_delete( # pylint: disable=inconsistent-return-statements """Drops a distributed availability group between Sql On-Prem and Sql Managed Instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param distributed_availability_group_name: The distributed availability group name. + :param distributed_availability_group_name: The distributed availability group name. Required. :type distributed_availability_group_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -647,80 +673,77 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, distributed_availability_group_name=distributed_availability_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore def _update_initial( self, resource_group_name: str, managed_instance_name: str, distributed_availability_group_name: str, - parameters: _models.DistributedAvailabilityGroup, + parameters: Union[_models.DistributedAvailabilityGroup, IO], **kwargs: Any ) -> Optional[_models.DistributedAvailabilityGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.DistributedAvailabilityGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.DistributedAvailabilityGroup]] - _json = self._serialize.body(parameters, 'DistributedAvailabilityGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DistributedAvailabilityGroup") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, distributed_availability_group_name=distributed_availability_group_name, @@ -728,7 +751,8 @@ def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -736,10 +760,9 @@ def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -748,39 +771,79 @@ def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('DistributedAvailabilityGroup', pipeline_response) + deserialized = self._deserialize("DistributedAvailabilityGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore - - @distributed_trace + @overload def begin_update( self, resource_group_name: str, managed_instance_name: str, distributed_availability_group_name: str, parameters: _models.DistributedAvailabilityGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.DistributedAvailabilityGroup]: """Updates a distributed availability group replication mode. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param distributed_availability_group_name: The distributed availability group name. + :param distributed_availability_group_name: The distributed availability group name. Required. :type distributed_availability_group_name: str - :param parameters: The distributed availability group info. + :param parameters: The distributed availability group info. Required. :type parameters: ~azure.mgmt.sql.models.DistributedAvailabilityGroup - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 DistributedAvailabilityGroup or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.DistributedAvailabilityGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + distributed_availability_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.DistributedAvailabilityGroup]: + """Updates a distributed availability group replication mode. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param distributed_availability_group_name: The distributed availability group name. Required. + :type distributed_availability_group_name: str + :param parameters: The distributed availability group info. Required. + :type parameters: IO + :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 @@ -792,20 +855,55 @@ def begin_update( :return: An instance of LROPoller that returns either DistributedAvailabilityGroup or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.DistributedAvailabilityGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + distributed_availability_group_name: str, + parameters: Union[_models.DistributedAvailabilityGroup, IO], + **kwargs: Any + ) -> LROPoller[_models.DistributedAvailabilityGroup]: + """Updates a distributed availability group replication mode. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param distributed_availability_group_name: The distributed availability group name. Required. + :type distributed_availability_group_name: str + :param parameters: The distributed availability group info. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.DistributedAvailabilityGroup 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. + :return: An instance of LROPoller that returns either DistributedAvailabilityGroup or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.DistributedAvailabilityGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DistributedAvailabilityGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DistributedAvailabilityGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -814,36 +912,32 @@ def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('DistributedAvailabilityGroup', pipeline_response) + deserialized = self._deserialize("DistributedAvailabilityGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/distributedAvailabilityGroups/{distributedAvailabilityGroupName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_elastic_pool_activities_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_elastic_pool_activities_operations.py index 4f7064d92cd83..205bd402a50ad 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_elastic_pool_activities_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_elastic_pool_activities_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,50 +24,47 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_elastic_pool_request( - subscription_id: str, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any + resource_group_name: str, server_name: str, elastic_pool_name: str, subscription_id: str, **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', "2014-04-01")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/elasticPoolActivity") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/elasticPoolActivity", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ElasticPoolActivitiesOperations: """ @@ -84,53 +85,44 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_elastic_pool( - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any - ) -> Iterable[_models.ElasticPoolActivityListResult]: + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any + ) -> Iterable["_models.ElasticPoolActivity"]: """Returns elastic pool activities. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param elastic_pool_name: The name of the elastic pool for which to get the current activity. + Required. :type elastic_pool_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ElasticPoolActivityListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ElasticPoolActivityListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ElasticPoolActivity or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ElasticPoolActivity] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ElasticPoolActivityListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ElasticPoolActivityListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_elastic_pool_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_elastic_pool.metadata['url'], + template_url=self.list_by_elastic_pool.metadata["url"], headers=_headers, params=_params, ) @@ -138,17 +130,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_elastic_pool_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - elastic_pool_name=elastic_pool_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -164,10 +146,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -177,8 +157,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_elastic_pool.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/elasticPoolActivity"} # type: ignore + list_by_elastic_pool.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/elasticPoolActivity"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_elastic_pool_database_activities_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_elastic_pool_database_activities_operations.py index 1c92ac4eb93d0..66c3df66c5a7b 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_elastic_pool_database_activities_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_elastic_pool_database_activities_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,50 +24,47 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_elastic_pool_request( - subscription_id: str, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any + resource_group_name: str, server_name: str, elastic_pool_name: str, subscription_id: str, **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', "2014-04-01")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/elasticPoolDatabaseActivity") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/elasticPoolDatabaseActivity", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ElasticPoolDatabaseActivitiesOperations: """ @@ -84,54 +85,44 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_elastic_pool( - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any - ) -> Iterable[_models.ElasticPoolDatabaseActivityListResult]: + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any + ) -> Iterable["_models.ElasticPoolDatabaseActivity"]: """Returns activity on databases inside of an elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool. + :param elastic_pool_name: The name of the elastic pool. Required. :type elastic_pool_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ElasticPoolDatabaseActivityListResult or the - result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ElasticPoolDatabaseActivityListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ElasticPoolDatabaseActivity or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ElasticPoolDatabaseActivity] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ElasticPoolDatabaseActivityListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ElasticPoolDatabaseActivityListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_elastic_pool_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_elastic_pool.metadata['url'], + template_url=self.list_by_elastic_pool.metadata["url"], headers=_headers, params=_params, ) @@ -139,17 +130,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_elastic_pool_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - elastic_pool_name=elastic_pool_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -165,10 +146,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -178,8 +157,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_elastic_pool.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/elasticPoolDatabaseActivity"} # type: ignore + list_by_elastic_pool.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/elasticPoolDatabaseActivity"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_elastic_pool_operations_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_elastic_pool_operations_operations.py index 98c4e03fc5b03..182585e488ab0 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_elastic_pool_operations_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_elastic_pool_operations_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_cancel_request( resource_group_name: str, server_name: str, @@ -37,67 +44,59 @@ def build_cancel_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/operations/{operationId}/cancel") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/operations/{operationId}/cancel", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, 'str'), - "operationId": _SERIALIZER.url("operation_id", operation_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, "str"), + "operationId": _SERIALIZER.url("operation_id", operation_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) def build_list_by_elastic_pool_request( - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, elastic_pool_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/operations") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/operations", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ElasticPoolOperationsOperations: """ @@ -118,47 +117,35 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def cancel( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - operation_id: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, elastic_pool_name: str, operation_id: str, **kwargs: Any ) -> None: """Cancels the asynchronous operation on the elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: + :param elastic_pool_name: Required. :type elastic_pool_name: str - :param operation_id: The operation identifier. + :param operation_id: The operation identifier. Required. :type operation_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_cancel_request( resource_group_name=resource_group_name, server_name=server_name, @@ -166,7 +153,7 @@ def cancel( # pylint: disable=inconsistent-return-statements operation_id=operation_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.cancel.metadata['url'], + template_url=self.cancel.metadata["url"], headers=_headers, params=_params, ) @@ -174,10 +161,9 @@ def cancel( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -187,55 +173,46 @@ def cancel( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - cancel.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/operations/{operationId}/cancel"} # type: ignore - + cancel.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/operations/{operationId}/cancel"} # type: ignore @distributed_trace def list_by_elastic_pool( - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any - ) -> Iterable[_models.ElasticPoolOperationListResult]: + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any + ) -> Iterable["_models.ElasticPoolOperation"]: """Gets a list of operations performed on the elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: + :param elastic_pool_name: Required. :type elastic_pool_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ElasticPoolOperationListResult or the result of + :return: An iterator like instance of either ElasticPoolOperation or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ElasticPoolOperationListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ElasticPoolOperation] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ElasticPoolOperationListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ElasticPoolOperationListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_elastic_pool_request( resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_elastic_pool.metadata['url'], + template_url=self.list_by_elastic_pool.metadata["url"], headers=_headers, params=_params, ) @@ -243,17 +220,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_elastic_pool_request( - resource_group_name=resource_group_name, - server_name=server_name, - elastic_pool_name=elastic_pool_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -269,10 +236,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -282,8 +247,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_elastic_pool.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/operations"} # type: ignore + list_by_elastic_pool.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/operations"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_elastic_pools_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_elastic_pools_operations.py index e67135aef39ed..72c7907cae646 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_elastic_pools_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_elastic_pools_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,18 +26,21 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_metrics_request( - subscription_id: str, resource_group_name: str, server_name: str, elastic_pool_name: str, + subscription_id: str, *, filter: str, **kwargs: Any @@ -41,311 +48,251 @@ def build_list_metrics_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', "2014-04-01")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/metrics") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/metrics", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') - _params['$filter'] = _SERIALIZER.query("filter", filter, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + _params["$filter"] = _SERIALIZER.query("filter", filter, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_metric_definitions_request( - subscription_id: str, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any + resource_group_name: str, server_name: str, elastic_pool_name: str, subscription_id: str, **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', "2014-04-01")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/metricDefinitions") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/metricDefinitions", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - *, - skip: Optional[int] = None, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, *, skip: Optional[int] = None, **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', "2021-08-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-08-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if skip is not None: - _params['$skip'] = _SERIALIZER.query("skip", skip, 'long') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$skip"] = _SERIALIZER.query("skip", skip, "int") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, elastic_pool_name: str, subscription_id: str, **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', "2021-08-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-08-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - subscription_id: str, - *, - json: Optional[_models.ElasticPool] = None, - content: Any = None, - **kwargs: Any +def build_create_or_update_request( + resource_group_name: str, server_name: str, elastic_pool_name: str, subscription_id: str, **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', "2021-08-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-08-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_request_initial( - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - subscription_id: str, - **kwargs: Any +def build_delete_request( + resource_group_name: str, server_name: str, elastic_pool_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-08-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) -def build_update_request_initial( - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - subscription_id: str, - *, - json: Optional[_models.ElasticPoolUpdate] = None, - content: Any = None, - **kwargs: Any +def build_update_request( + resource_group_name: str, server_name: str, elastic_pool_name: str, subscription_id: str, **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', "2021-08-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-08-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) -def build_failover_request_initial( - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - subscription_id: str, - **kwargs: Any +def build_failover_request( + resource_group_name: str, server_name: str, elastic_pool_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-08-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/failover") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/failover", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "elasticPoolName": _SERIALIZER.url("elastic_pool_name", elastic_pool_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) class ElasticPoolsOperations: """ @@ -366,56 +313,47 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_metrics( - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - filter: str, - **kwargs: Any - ) -> Iterable[_models.MetricListResult]: + self, resource_group_name: str, server_name: str, elastic_pool_name: str, filter: str, **kwargs: Any + ) -> Iterable["_models.Metric"]: """Returns elastic pool metrics. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool. + :param elastic_pool_name: The name of the elastic pool. Required. :type elastic_pool_name: str :param filter: An OData filter expression that describes a subset of metrics to return. + Required. :type filter: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either MetricListResult or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.MetricListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Metric or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.Metric] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.MetricListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.MetricListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_metrics_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, - api_version=api_version, + subscription_id=self._config.subscription_id, filter=filter, - template_url=self.list_metrics.metadata['url'], + api_version=api_version, + template_url=self.list_metrics.metadata["url"], headers=_headers, params=_params, ) @@ -423,18 +361,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_metrics_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - elastic_pool_name=elastic_pool_name, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -450,10 +377,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -463,58 +388,47 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_metrics.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/metrics"} # type: ignore + list_metrics.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/metrics"} # type: ignore @distributed_trace def list_metric_definitions( - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any - ) -> Iterable[_models.MetricDefinitionListResult]: + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any + ) -> Iterable["_models.MetricDefinition"]: """Returns elastic pool metric definitions. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool. + :param elastic_pool_name: The name of the elastic pool. Required. :type elastic_pool_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either MetricDefinitionListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.MetricDefinitionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either MetricDefinition or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.MetricDefinition] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.MetricDefinitionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.MetricDefinitionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_metric_definitions_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_metric_definitions.metadata['url'], + template_url=self.list_metric_definitions.metadata["url"], headers=_headers, params=_params, ) @@ -522,17 +436,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_metric_definitions_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - elastic_pool_name=elastic_pool_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -548,10 +452,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -561,58 +463,47 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_metric_definitions.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/metricDefinitions"} # type: ignore + list_metric_definitions.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/metricDefinitions"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - skip: Optional[int] = None, - **kwargs: Any - ) -> Iterable[_models.ElasticPoolListResult]: + self, resource_group_name: str, server_name: str, skip: Optional[int] = None, **kwargs: Any + ) -> Iterable["_models.ElasticPool"]: """Gets all elastic pools in a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param skip: The number of elements in the collection to skip. Default value is None. - :type skip: long - :keyword api_version: Api Version. Default value is "2021-08-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :type skip: int :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ElasticPoolListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ElasticPoolListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ElasticPool or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ElasticPool] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ElasticPoolListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ElasticPoolListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, - api_version=api_version, skip=skip, - template_url=self.list_by_server.metadata['url'], + api_version=api_version, + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -620,17 +511,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - skip=skip, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -646,10 +527,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -659,56 +538,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any ) -> _models.ElasticPool: """Gets an elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool. + :param elastic_pool_name: The name of the elastic pool. Required. :type elastic_pool_name: str - :keyword api_version: Api Version. Default value is "2021-08-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ElasticPool, or the result of cls(response) + :return: ElasticPool or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ElasticPool - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ElasticPool] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ElasticPool] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -716,49 +583,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ElasticPool', pipeline_response) + deserialized = self._deserialize("ElasticPool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, elastic_pool_name: str, - parameters: _models.ElasticPool, + parameters: Union[_models.ElasticPool, IO], **kwargs: Any ) -> Optional[_models.ElasticPool]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ElasticPool]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ElasticPool]] - _json = self._serialize.body(parameters, 'ElasticPool') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ElasticPool") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, @@ -766,7 +635,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -774,10 +644,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -786,42 +655,82 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ElasticPool', pipeline_response) + deserialized = self._deserialize("ElasticPool", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ElasticPool', pipeline_response) + deserialized = self._deserialize("ElasticPool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, elastic_pool_name: str, parameters: _models.ElasticPool, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ElasticPool]: """Creates or updates an elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool. + :param elastic_pool_name: The name of the elastic pool. Required. :type elastic_pool_name: str - :param parameters: The elastic pool parameters. + :param parameters: The elastic pool parameters. Required. :type parameters: ~azure.mgmt.sql.models.ElasticPool - :keyword api_version: Api Version. Default value is "2021-08-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ElasticPool or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ElasticPool] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + elastic_pool_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ElasticPool]: + """Creates or updates an elastic pool. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param elastic_pool_name: The name of the elastic pool. Required. + :type elastic_pool_name: str + :param parameters: The elastic pool parameters. Required. + :type parameters: IO + :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 @@ -833,20 +742,54 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ElasticPool or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ElasticPool] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + elastic_pool_name: str, + parameters: Union[_models.ElasticPool, IO], + **kwargs: Any + ) -> LROPoller[_models.ElasticPool]: + """Creates or updates an elastic pool. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param elastic_pool_name: The name of the elastic pool. Required. + :type elastic_pool_name: str + :param parameters: The elastic pool parameters. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ElasticPool 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. + :return: An instance of LROPoller that returns either ElasticPool or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ElasticPool] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ElasticPool] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ElasticPool] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -855,66 +798,55 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ElasticPool', pipeline_response) + deserialized = self._deserialize("ElasticPool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -922,10 +854,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -935,29 +866,21 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes an elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool. + :param elastic_pool_name: The name of the elastic pool. Required. :type elastic_pool_name: str - :keyword api_version: Api Version. Default value is "2021-08-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -968,80 +891,77 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore def _update_initial( self, resource_group_name: str, server_name: str, elastic_pool_name: str, - parameters: _models.ElasticPoolUpdate, + parameters: Union[_models.ElasticPoolUpdate, IO], **kwargs: Any ) -> Optional[_models.ElasticPool]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ElasticPool]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ElasticPool]] - _json = self._serialize.body(parameters, 'ElasticPoolUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ElasticPoolUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, @@ -1049,7 +969,8 @@ def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1057,10 +978,9 @@ def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1069,39 +989,79 @@ def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ElasticPool', pipeline_response) + deserialized = self._deserialize("ElasticPool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore - + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore - @distributed_trace + @overload def begin_update( self, resource_group_name: str, server_name: str, elastic_pool_name: str, parameters: _models.ElasticPoolUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ElasticPool]: """Updates an elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool. + :param elastic_pool_name: The name of the elastic pool. Required. :type elastic_pool_name: str - :param parameters: The elastic pool update parameters. + :param parameters: The elastic pool update parameters. Required. :type parameters: ~azure.mgmt.sql.models.ElasticPoolUpdate - :keyword api_version: Api Version. Default value is "2021-08-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ElasticPool or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ElasticPool] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_update( + self, + resource_group_name: str, + server_name: str, + elastic_pool_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ElasticPool]: + """Updates an elastic pool. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param elastic_pool_name: The name of the elastic pool. Required. + :type elastic_pool_name: str + :param parameters: The elastic pool update parameters. Required. + :type parameters: IO + :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 @@ -1113,20 +1073,55 @@ def begin_update( :return: An instance of LROPoller that returns either ElasticPool or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ElasticPool] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_update( + self, + resource_group_name: str, + server_name: str, + elastic_pool_name: str, + parameters: Union[_models.ElasticPoolUpdate, IO], + **kwargs: Any + ) -> LROPoller[_models.ElasticPool]: + """Updates an elastic pool. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param elastic_pool_name: The name of the elastic pool. Required. + :type elastic_pool_name: str + :param parameters: The elastic pool update parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ElasticPoolUpdate 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. + :return: An instance of LROPoller that returns either ElasticPool or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ElasticPool] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ElasticPool] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ElasticPool] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -1135,66 +1130,55 @@ def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ElasticPool', pipeline_response) + deserialized = self._deserialize("ElasticPool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}"} # type: ignore def _failover_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_failover_request_initial( + request = build_failover_request( resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._failover_initial.metadata['url'], + template_url=self._failover_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1202,10 +1186,9 @@ def _failover_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1215,29 +1198,21 @@ def _failover_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _failover_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/failover"} # type: ignore - + _failover_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/failover"} # type: ignore @distributed_trace - def begin_failover( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - elastic_pool_name: str, - **kwargs: Any + def begin_failover( + self, resource_group_name: str, server_name: str, elastic_pool_name: str, **kwargs: Any ) -> LROPoller[None]: """Failovers an elastic pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param elastic_pool_name: The name of the elastic pool to failover. + :param elastic_pool_name: The name of the elastic pool to failover. Required. :type elastic_pool_name: str - :keyword api_version: Api Version. Default value is "2021-08-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1248,53 +1223,46 @@ def begin_failover( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-08-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._failover_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, elastic_pool_name=elastic_pool_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_failover.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/failover"} # type: ignore + begin_failover.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/failover"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_encryption_protectors_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_encryption_protectors_operations.py index cb99deea3695d..87c35bfad4e02 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_encryption_protectors_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_encryption_protectors_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,48 +26,45 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -76,83 +77,72 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "encryptionProtectorName": _SERIALIZER.url("encryption_protector_name", encryption_protector_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "encryptionProtectorName": _SERIALIZER.url("encryption_protector_name", encryption_protector_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, server_name: str, encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], subscription_id: str, - *, - json: Optional[_models.EncryptionProtector] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "encryptionProtectorName": _SERIALIZER.url("encryption_protector_name", encryption_protector_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "encryptionProtectorName": _SERIALIZER.url("encryption_protector_name", encryption_protector_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_revalidate_request_initial( +def build_revalidate_request( resource_group_name: str, server_name: str, encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], @@ -161,27 +151,26 @@ def build_revalidate_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}/revalidate") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}/revalidate", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "encryptionProtectorName": _SERIALIZER.url("encryption_protector_name", encryption_protector_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "encryptionProtectorName": _SERIALIZER.url("encryption_protector_name", encryption_protector_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) class EncryptionProtectorsOperations: """ @@ -202,49 +191,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.EncryptionProtectorListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.EncryptionProtector"]: """Gets a list of server encryption protectors. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either EncryptionProtectorListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.EncryptionProtectorListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either EncryptionProtector or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.EncryptionProtector] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.EncryptionProtectorListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.EncryptionProtectorListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -252,16 +232,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -277,10 +248,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -290,11 +259,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector"} # type: ignore @distributed_trace def get( @@ -307,39 +274,34 @@ def get( """Gets a server encryption protector. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param encryption_protector_name: The name of the encryption protector to be retrieved. + "current" Required. :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: EncryptionProtector, or the result of cls(response) + :return: EncryptionProtector or the result of cls(response) :rtype: ~azure.mgmt.sql.models.EncryptionProtector - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.EncryptionProtector] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.EncryptionProtector] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, encryption_protector_name=encryption_protector_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -347,49 +309,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('EncryptionProtector', pipeline_response) + deserialized = self._deserialize("EncryptionProtector", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], - parameters: _models.EncryptionProtector, + parameters: Union[_models.EncryptionProtector, IO], **kwargs: Any ) -> Optional[_models.EncryptionProtector]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.EncryptionProtector]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.EncryptionProtector]] - _json = self._serialize.body(parameters, 'EncryptionProtector') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "EncryptionProtector") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, encryption_protector_name=encryption_protector_name, @@ -397,7 +361,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -405,10 +370,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -417,39 +381,41 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('EncryptionProtector', pipeline_response) + deserialized = self._deserialize("EncryptionProtector", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], parameters: _models.EncryptionProtector, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.EncryptionProtector]: """Updates an existing encryption protector. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param encryption_protector_name: The name of the encryption protector to be updated. + :param encryption_protector_name: The name of the encryption protector to be updated. "current" + Required. :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName - :param parameters: The requested encryption protector resource state. + :param parameters: The requested encryption protector resource state. Required. :type parameters: ~azure.mgmt.sql.models.EncryptionProtector - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -461,20 +427,96 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either EncryptionProtector or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.EncryptionProtector] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.EncryptionProtector]: + """Updates an existing encryption protector. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param encryption_protector_name: The name of the encryption protector to be updated. "current" + Required. + :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName + :param parameters: The requested encryption protector resource state. Required. + :type parameters: IO + :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 EncryptionProtector or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.EncryptionProtector] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], + parameters: Union[_models.EncryptionProtector, IO], + **kwargs: Any + ) -> LROPoller[_models.EncryptionProtector]: + """Updates an existing encryption protector. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param encryption_protector_name: The name of the encryption protector to be updated. "current" + Required. + :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName + :param parameters: The requested encryption protector resource state. Is either a model type or + a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.EncryptionProtector 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. + :return: An instance of LROPoller that returns either EncryptionProtector or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.EncryptionProtector] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.EncryptionProtector] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.EncryptionProtector] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -483,39 +525,35 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('EncryptionProtector', pipeline_response) + deserialized = self._deserialize("EncryptionProtector", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore def _revalidate_initial( # pylint: disable=inconsistent-return-statements self, @@ -524,25 +562,22 @@ def _revalidate_initial( # pylint: disable=inconsistent-return-statements encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_revalidate_request_initial( + request = build_revalidate_request( resource_group_name=resource_group_name, server_name=server_name, encryption_protector_name=encryption_protector_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._revalidate_initial.metadata['url'], + template_url=self._revalidate_initial.metadata["url"], headers=_headers, params=_params, ) @@ -550,10 +585,9 @@ def _revalidate_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -563,11 +597,10 @@ def _revalidate_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _revalidate_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}/revalidate"} # type: ignore - + _revalidate_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}/revalidate"} # type: ignore @distributed_trace - def begin_revalidate( # pylint: disable=inconsistent-return-statements + def begin_revalidate( self, resource_group_name: str, server_name: str, @@ -577,15 +610,13 @@ def begin_revalidate( # pylint: disable=inconsistent-return-statements """Revalidates an existing encryption protector. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param encryption_protector_name: The name of the encryption protector to be updated. + :param encryption_protector_name: The name of the encryption protector to be updated. "current" + Required. :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -596,53 +627,46 @@ def begin_revalidate( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._revalidate_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, encryption_protector_name=encryption_protector_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_revalidate.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}/revalidate"} # type: ignore + begin_revalidate.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}/revalidate"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_endpoint_certificates_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_endpoint_certificates_operations.py index 92b26e06b62f6..5d848e35a5191 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_endpoint_certificates_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_endpoint_certificates_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,87 +24,78 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_instance_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/endpointCertificates") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/endpointCertificates", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - managed_instance_name: str, - endpoint_type: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, endpoint_type: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/endpointCertificates/{endpointType}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/endpointCertificates/{endpointType}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "endpointType": _SERIALIZER.url("endpoint_type", endpoint_type, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "endpointType": _SERIALIZER.url("endpoint_type", endpoint_type, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class EndpointCertificatesOperations: """ @@ -121,49 +116,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> Iterable[_models.EndpointCertificateListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.EndpointCertificate"]: """List certificates used on endpoints on the target instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either EndpointCertificateListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.EndpointCertificateListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either EndpointCertificate or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.EndpointCertificate] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.EndpointCertificateListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.EndpointCertificateListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -171,16 +157,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -196,10 +173,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -209,56 +184,45 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/endpointCertificates"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/endpointCertificates"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - managed_instance_name: str, - endpoint_type: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, endpoint_type: str, **kwargs: Any ) -> _models.EndpointCertificate: """Gets a certificate used on the endpoint with the given id. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param endpoint_type: Type of the endpoint whose certificate the customer is looking for. + Required. :type endpoint_type: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: EndpointCertificate, or the result of cls(response) + :return: EndpointCertificate or the result of cls(response) :rtype: ~azure.mgmt.sql.models.EndpointCertificate - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.EndpointCertificate] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.EndpointCertificate] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, endpoint_type=endpoint_type, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -266,22 +230,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('EndpointCertificate', pipeline_response) + deserialized = self._deserialize("EndpointCertificate", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/endpointCertificates/{endpointType}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/endpointCertificates/{endpointType}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_extended_database_blob_auditing_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_extended_database_blob_auditing_policies_operations.py index 3d55577accf2f..951983e96f00a 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_extended_database_blob_auditing_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_extended_database_blob_auditing_policies_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,140 +24,118 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_database_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings/{blobAuditingPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings/{blobAuditingPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "blobAuditingPolicyName": _SERIALIZER.url("blob_auditing_policy_name", blob_auditing_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "blobAuditingPolicyName": _SERIALIZER.url("blob_auditing_policy_name", blob_auditing_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - *, - json: Optional[_models.ExtendedDatabaseBlobAuditingPolicy] = None, - content: Any = None, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings/{blobAuditingPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings/{blobAuditingPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "blobAuditingPolicyName": _SERIALIZER.url("blob_auditing_policy_name", blob_auditing_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "blobAuditingPolicyName": _SERIALIZER.url("blob_auditing_policy_name", blob_auditing_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + class ExtendedDatabaseBlobAuditingPoliciesOperations: """ @@ -174,54 +156,44 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.ExtendedDatabaseBlobAuditingPolicyListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.ExtendedDatabaseBlobAuditingPolicy"]: """Lists extended auditing settings of a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ExtendedDatabaseBlobAuditingPolicyListResult or - the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ExtendedDatabaseBlobAuditingPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ExtendedDatabaseBlobAuditingPolicy or the result + of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ExtendedDatabaseBlobAuditingPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ExtendedDatabaseBlobAuditingPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ExtendedDatabaseBlobAuditingPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -229,17 +201,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -255,10 +217,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -268,53 +228,41 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> _models.ExtendedDatabaseBlobAuditingPolicy: """Gets an extended database's blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is "default". Note that overriding this default value may result in unsupported behavior. :paramtype blob_auditing_policy_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ExtendedDatabaseBlobAuditingPolicy, or the result of cls(response) + :return: ExtendedDatabaseBlobAuditingPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ExtendedDatabaseBlobAuditingPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ExtendedDatabaseBlobAuditingPolicy] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ExtendedDatabaseBlobAuditingPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -322,7 +270,7 @@ def get( subscription_id=self._config.subscription_id, blob_auditing_policy_name=blob_auditing_policy_name, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -330,71 +278,142 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ExtendedDatabaseBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ExtendedDatabaseBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.ExtendedDatabaseBlobAuditingPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.ExtendedDatabaseBlobAuditingPolicy: """Creates or updates an extended database's blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The extended database blob auditing policy. + :param parameters: The extended database blob auditing policy. Required. :type parameters: ~azure.mgmt.sql.models.ExtendedDatabaseBlobAuditingPolicy + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is "default". Note that overriding this default value may result in unsupported behavior. :paramtype blob_auditing_policy_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ExtendedDatabaseBlobAuditingPolicy, or the result of cls(response) + :return: ExtendedDatabaseBlobAuditingPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ExtendedDatabaseBlobAuditingPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.ExtendedDatabaseBlobAuditingPolicy: + """Creates or updates an extended database's blob auditing policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The extended database blob auditing policy. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is + "default". Note that overriding this default value may result in unsupported behavior. + :paramtype blob_auditing_policy_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ExtendedDatabaseBlobAuditingPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ExtendedDatabaseBlobAuditingPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.ExtendedDatabaseBlobAuditingPolicy, IO], + **kwargs: Any + ) -> _models.ExtendedDatabaseBlobAuditingPolicy: + """Creates or updates an extended database's blob auditing policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The extended database blob auditing policy. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.ExtendedDatabaseBlobAuditingPolicy or IO + :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is + "default". Note that overriding this default value may result in unsupported behavior. + :paramtype blob_auditing_policy_name: str + :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 + :return: ExtendedDatabaseBlobAuditingPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ExtendedDatabaseBlobAuditingPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ExtendedDatabaseBlobAuditingPolicy] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ExtendedDatabaseBlobAuditingPolicy] - _json = self._serialize.body(parameters, 'ExtendedDatabaseBlobAuditingPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ExtendedDatabaseBlobAuditingPolicy") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -405,7 +424,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -413,10 +433,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -424,15 +443,14 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('ExtendedDatabaseBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ExtendedDatabaseBlobAuditingPolicy", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ExtendedDatabaseBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ExtendedDatabaseBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_extended_server_blob_auditing_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_extended_server_blob_auditing_policies_operations.py index 8289136c78342..996dcfde90557 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_extended_server_blob_auditing_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_extended_server_blob_auditing_policies_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,134 +26,113 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_get_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any -) -> HttpRequest: + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_get_request(resource_group_name: str, server_name: str, subscription_id: str, **kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "blobAuditingPolicyName": _SERIALIZER.url("blob_auditing_policy_name", blob_auditing_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "blobAuditingPolicyName": _SERIALIZER.url("blob_auditing_policy_name", blob_auditing_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - resource_group_name: str, - server_name: str, - subscription_id: str, - *, - json: Optional[_models.ExtendedServerBlobAuditingPolicy] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, server_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "blobAuditingPolicyName": _SERIALIZER.url("blob_auditing_policy_name", blob_auditing_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "blobAuditingPolicyName": _SERIALIZER.url("blob_auditing_policy_name", blob_auditing_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + class ExtendedServerBlobAuditingPoliciesOperations: """ @@ -170,50 +153,41 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.ExtendedServerBlobAuditingPolicyListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.ExtendedServerBlobAuditingPolicy"]: """Lists extended auditing settings of a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ExtendedServerBlobAuditingPolicyListResult or the - result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ExtendedServerBlobAuditingPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ExtendedServerBlobAuditingPolicy or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ExtendedServerBlobAuditingPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ExtendedServerBlobAuditingPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ExtendedServerBlobAuditingPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -221,16 +195,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -246,10 +211,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -259,57 +222,46 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, **kwargs: Any ) -> _models.ExtendedServerBlobAuditingPolicy: """Gets an extended server's blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is "default". Note that overriding this default value may result in unsupported behavior. :paramtype blob_auditing_policy_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ExtendedServerBlobAuditingPolicy, or the result of cls(response) + :return: ExtendedServerBlobAuditingPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ExtendedServerBlobAuditingPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ExtendedServerBlobAuditingPolicy] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ExtendedServerBlobAuditingPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, blob_auditing_policy_name=blob_auditing_policy_name, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -317,49 +269,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ExtendedServerBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ExtendedServerBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, - parameters: _models.ExtendedServerBlobAuditingPolicy, + parameters: Union[_models.ExtendedServerBlobAuditingPolicy, IO], **kwargs: Any ) -> Optional[_models.ExtendedServerBlobAuditingPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ExtendedServerBlobAuditingPolicy]] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ExtendedServerBlobAuditingPolicy]] - _json = self._serialize.body(parameters, 'ExtendedServerBlobAuditingPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ExtendedServerBlobAuditingPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, @@ -367,7 +321,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -375,10 +330,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -387,39 +341,40 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ExtendedServerBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ExtendedServerBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, parameters: _models.ExtendedServerBlobAuditingPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ExtendedServerBlobAuditingPolicy]: """Creates or updates an extended server's blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param parameters: Properties of extended blob auditing policy. + :param parameters: Properties of extended blob auditing policy. Required. :type parameters: ~azure.mgmt.sql.models.ExtendedServerBlobAuditingPolicy + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is "default". Note that overriding this default value may result in unsupported behavior. :paramtype blob_auditing_policy_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -431,21 +386,95 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ExtendedServerBlobAuditingPolicy or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ExtendedServerBlobAuditingPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ExtendedServerBlobAuditingPolicy]: + """Creates or updates an extended server's blob auditing policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: Properties of extended blob auditing policy. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is + "default". Note that overriding this default value may result in unsupported behavior. + :paramtype blob_auditing_policy_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 ExtendedServerBlobAuditingPolicy or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ExtendedServerBlobAuditingPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + parameters: Union[_models.ExtendedServerBlobAuditingPolicy, IO], + **kwargs: Any + ) -> LROPoller[_models.ExtendedServerBlobAuditingPolicy]: + """Creates or updates an extended server's blob auditing policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: Properties of extended blob auditing policy. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.ExtendedServerBlobAuditingPolicy or IO + :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is + "default". Note that overriding this default value may result in unsupported behavior. + :paramtype blob_auditing_policy_name: str + :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. + :return: An instance of LROPoller that returns either ExtendedServerBlobAuditingPolicy or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ExtendedServerBlobAuditingPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ExtendedServerBlobAuditingPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ExtendedServerBlobAuditingPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -454,36 +483,32 @@ def begin_create_or_update( blob_auditing_policy_name=blob_auditing_policy_name, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ExtendedServerBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ExtendedServerBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_failover_groups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_failover_groups_operations.py index 0ccef616b11c9..e2ba802b9a400 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_failover_groups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_failover_groups_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,291 +26,238 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( - resource_group_name: str, - server_name: str, - failover_group_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, failover_group_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - resource_group_name: str, - server_name: str, - failover_group_name: str, - subscription_id: str, - *, - json: Optional[_models.FailoverGroup] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, server_name: str, failover_group_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) - - -def build_delete_request_initial( - resource_group_name: str, - server_name: str, - failover_group_name: str, - subscription_id: str, - **kwargs: Any + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_delete_request( + resource_group_name: str, server_name: str, failover_group_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') - - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) - - -def build_update_request_initial( - resource_group_name: str, - server_name: str, - failover_group_name: str, - subscription_id: str, - *, - json: Optional[_models.FailoverGroupUpdate] = None, - content: Any = None, - **kwargs: Any + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) + + +def build_update_request( + resource_group_name: str, server_name: str, failover_group_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_failover_request_initial( - resource_group_name: str, - server_name: str, - failover_group_name: str, - subscription_id: str, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_failover_request( + resource_group_name: str, server_name: str, failover_group_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/failover") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/failover", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_force_failover_allow_data_loss_request_initial( - resource_group_name: str, - server_name: str, - failover_group_name: str, - subscription_id: str, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_force_failover_allow_data_loss_request( + resource_group_name: str, server_name: str, failover_group_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class FailoverGroupsOperations: """ @@ -327,51 +278,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, failover_group_name: str, **kwargs: Any ) -> _models.FailoverGroup: """Gets a failover group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server containing the failover group. + :param server_name: The name of the server containing the failover group. Required. :type server_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: FailoverGroup, or the result of cls(response) + :return: FailoverGroup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.FailoverGroup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.FailoverGroup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.FailoverGroup] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -379,49 +319,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, failover_group_name: str, - parameters: _models.FailoverGroup, + parameters: Union[_models.FailoverGroup, IO], **kwargs: Any ) -> Optional[_models.FailoverGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.FailoverGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.FailoverGroup]] - _json = self._serialize.body(parameters, 'FailoverGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "FailoverGroup") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, @@ -429,7 +371,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -437,10 +380,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -449,42 +391,82 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, failover_group_name: str, parameters: _models.FailoverGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.FailoverGroup]: """Creates or updates a failover group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server containing the failover group. + :param server_name: The name of the server containing the failover group. Required. :type server_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :param parameters: The failover group parameters. + :param parameters: The failover group parameters. Required. :type parameters: ~azure.mgmt.sql.models.FailoverGroup - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 FailoverGroup or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.FailoverGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + failover_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.FailoverGroup]: + """Creates or updates a failover group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server containing the failover group. Required. + :type server_name: str + :param failover_group_name: The name of the failover group. Required. + :type failover_group_name: str + :param parameters: The failover group parameters. Required. + :type parameters: IO + :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 @@ -496,20 +478,55 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either FailoverGroup or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.FailoverGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + failover_group_name: str, + parameters: Union[_models.FailoverGroup, IO], + **kwargs: Any + ) -> LROPoller[_models.FailoverGroup]: + """Creates or updates a failover group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server containing the failover group. Required. + :type server_name: str + :param failover_group_name: The name of the failover group. Required. + :type failover_group_name: str + :param parameters: The failover group parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.FailoverGroup 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. + :return: An instance of LROPoller that returns either FailoverGroup or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.FailoverGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.FailoverGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.FailoverGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -518,66 +535,55 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, failover_group_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -585,10 +591,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -598,29 +603,21 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - failover_group_name: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, server_name: str, failover_group_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes a failover group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server containing the failover group. + :param server_name: The name of the server containing the failover group. Required. :type server_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -631,80 +628,77 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore def _update_initial( self, resource_group_name: str, server_name: str, failover_group_name: str, - parameters: _models.FailoverGroupUpdate, + parameters: Union[_models.FailoverGroupUpdate, IO], **kwargs: Any ) -> Optional[_models.FailoverGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.FailoverGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.FailoverGroup]] - _json = self._serialize.body(parameters, 'FailoverGroupUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "FailoverGroupUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, @@ -712,7 +706,8 @@ def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -720,10 +715,9 @@ def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -732,39 +726,40 @@ def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore - - @distributed_trace + @overload def begin_update( self, resource_group_name: str, server_name: str, failover_group_name: str, parameters: _models.FailoverGroupUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.FailoverGroup]: """Updates a failover group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server containing the failover group. + :param server_name: The name of the server containing the failover group. Required. :type server_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :param parameters: The failover group parameters. + :param parameters: The failover group parameters. Required. :type parameters: ~azure.mgmt.sql.models.FailoverGroupUpdate - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -776,20 +771,94 @@ def begin_update( :return: An instance of LROPoller that returns either FailoverGroup or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.FailoverGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_update( + self, + resource_group_name: str, + server_name: str, + failover_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.FailoverGroup]: + """Updates a failover group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server containing the failover group. Required. + :type server_name: str + :param failover_group_name: The name of the failover group. Required. + :type failover_group_name: str + :param parameters: The failover group parameters. Required. + :type parameters: IO + :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 FailoverGroup or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.FailoverGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_update( + self, + resource_group_name: str, + server_name: str, + failover_group_name: str, + parameters: Union[_models.FailoverGroupUpdate, IO], + **kwargs: Any + ) -> LROPoller[_models.FailoverGroup]: + """Updates a failover group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server containing the failover group. Required. + :type server_name: str + :param failover_group_name: The name of the failover group. Required. + :type failover_group_name: str + :param parameters: The failover group parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.FailoverGroupUpdate 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. + :return: An instance of LROPoller that returns either FailoverGroup or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.FailoverGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.FailoverGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.FailoverGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -798,82 +867,70 @@ def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.FailoverGroupListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.FailoverGroup"]: """Lists the failover groups in a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server containing the failover group. + :param server_name: The name of the server containing the failover group. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either FailoverGroupListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.FailoverGroupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either FailoverGroup or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.FailoverGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.FailoverGroupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.FailoverGroupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -881,16 +938,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -906,10 +954,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -919,38 +965,29 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups"} # type: ignore def _failover_initial( - self, - resource_group_name: str, - server_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, failover_group_name: str, **kwargs: Any ) -> Optional[_models.FailoverGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.FailoverGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.FailoverGroup]] - - request = build_failover_request_initial( + request = build_failover_request( resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._failover_initial.metadata['url'], + template_url=self._failover_initial.metadata["url"], headers=_headers, params=_params, ) @@ -958,10 +995,9 @@ def _failover_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -970,36 +1006,28 @@ def _failover_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _failover_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/failover"} # type: ignore - + _failover_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/failover"} # type: ignore @distributed_trace def begin_failover( - self, - resource_group_name: str, - server_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, failover_group_name: str, **kwargs: Any ) -> LROPoller[_models.FailoverGroup]: """Fails over from the current primary server to this server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server containing the failover group. + :param server_name: The name of the server containing the failover group. Required. :type server_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1011,85 +1039,71 @@ def begin_failover( :return: An instance of LROPoller that returns either FailoverGroup or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.FailoverGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.FailoverGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.FailoverGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._failover_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_failover.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/failover"} # type: ignore + begin_failover.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/failover"} # type: ignore def _force_failover_allow_data_loss_initial( - self, - resource_group_name: str, - server_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, failover_group_name: str, **kwargs: Any ) -> Optional[_models.FailoverGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.FailoverGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.FailoverGroup]] - - request = build_force_failover_allow_data_loss_request_initial( + request = build_force_failover_allow_data_loss_request( resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._force_failover_allow_data_loss_initial.metadata['url'], + template_url=self._force_failover_allow_data_loss_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1097,10 +1111,9 @@ def _force_failover_allow_data_loss_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1109,37 +1122,29 @@ def _force_failover_allow_data_loss_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _force_failover_allow_data_loss_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss"} # type: ignore - + _force_failover_allow_data_loss_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss"} # type: ignore @distributed_trace def begin_force_failover_allow_data_loss( - self, - resource_group_name: str, - server_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, failover_group_name: str, **kwargs: Any ) -> LROPoller[_models.FailoverGroup]: """Fails over from the current primary server to this server. This operation might result in data loss. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server containing the failover group. + :param server_name: The name of the server containing the failover group. Required. :type server_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1151,55 +1156,48 @@ def begin_force_failover_allow_data_loss( :return: An instance of LROPoller that returns either FailoverGroup or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.FailoverGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.FailoverGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.FailoverGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._force_failover_allow_data_loss_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, failover_group_name=failover_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('FailoverGroup', pipeline_response) + deserialized = self._deserialize("FailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_force_failover_allow_data_loss.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss"} # type: ignore + begin_force_failover_allow_data_loss.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_firewall_rules_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_firewall_rules_operations.py index 63eae137a37b6..868ff1c78cfcb 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_firewall_rules_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_firewall_rules_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,211 +24,173 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( - resource_group_name: str, - server_name: str, - firewall_rule_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, firewall_rule_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "firewallRuleName": _SERIALIZER.url("firewall_rule_name", firewall_rule_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "firewallRuleName": _SERIALIZER.url("firewall_rule_name", firewall_rule_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( - resource_group_name: str, - server_name: str, - firewall_rule_name: str, - subscription_id: str, - *, - json: Optional[_models.FirewallRule] = None, - content: Any = None, - **kwargs: Any + resource_group_name: str, server_name: str, firewall_rule_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "firewallRuleName": _SERIALIZER.url("firewall_rule_name", firewall_rule_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "firewallRuleName": _SERIALIZER.url("firewall_rule_name", firewall_rule_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_delete_request( - resource_group_name: str, - server_name: str, - firewall_rule_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, firewall_rule_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "firewallRuleName": _SERIALIZER.url("firewall_rule_name", firewall_rule_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "firewallRuleName": _SERIALIZER.url("firewall_rule_name", firewall_rule_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_replace_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - *, - json: Optional[_models.FirewallRuleList] = None, - content: Any = None, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + class FirewallRulesOperations: """ @@ -245,51 +211,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - firewall_rule_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, firewall_rule_name: str, **kwargs: Any ) -> _models.FirewallRule: """Gets a firewall rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param firewall_rule_name: The name of the firewall rule. + :param firewall_rule_name: The name of the firewall rule. Required. :type firewall_rule_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: FirewallRule, or the result of cls(response) + :return: FirewallRule or the result of cls(response) :rtype: ~azure.mgmt.sql.models.FirewallRule - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.FirewallRule] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.FirewallRule] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, firewall_rule_name=firewall_rule_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -297,67 +252,132 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('FirewallRule', pipeline_response) + deserialized = self._deserialize("FirewallRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}"} # type: ignore + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}"} # type: ignore - - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, server_name: str, firewall_rule_name: str, parameters: _models.FirewallRule, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.FirewallRule: """Creates or updates a firewall rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param firewall_rule_name: The name of the firewall rule. + :param firewall_rule_name: The name of the firewall rule. Required. :type firewall_rule_name: str - :param parameters: The required parameters for creating or updating a firewall rule. + :param parameters: The required parameters for creating or updating a firewall rule. Required. :type parameters: ~azure.mgmt.sql.models.FirewallRule - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: FirewallRule or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.FirewallRule + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + firewall_rule_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.FirewallRule: + """Creates or updates a firewall rule. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param firewall_rule_name: The name of the firewall rule. Required. + :type firewall_rule_name: str + :param parameters: The required parameters for creating or updating a firewall rule. Required. + :type parameters: IO + :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: FirewallRule or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.FirewallRule + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + firewall_rule_name: str, + parameters: Union[_models.FirewallRule, IO], + **kwargs: Any + ) -> _models.FirewallRule: + """Creates or updates a firewall rule. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param firewall_rule_name: The name of the firewall rule. Required. + :type firewall_rule_name: str + :param parameters: The required parameters for creating or updating a firewall rule. Is either + a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.FirewallRule 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 - :return: FirewallRule, or the result of cls(response) + :return: FirewallRule or the result of cls(response) :rtype: ~azure.mgmt.sql.models.FirewallRule - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.FirewallRule] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.FirewallRule] - _json = self._serialize.body(parameters, 'FirewallRule') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "FirewallRule") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -367,7 +387,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -375,10 +396,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -386,63 +406,52 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('FirewallRule', pipeline_response) + deserialized = self._deserialize("FirewallRule", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('FirewallRule', pipeline_response) + deserialized = self._deserialize("FirewallRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}"} # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - firewall_rule_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, firewall_rule_name: str, **kwargs: Any ) -> None: """Deletes a firewall rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param firewall_rule_name: The name of the firewall rule. + :param firewall_rule_name: The name of the firewall rule. Required. :type firewall_rule_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, firewall_rule_name=firewall_rule_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -450,10 +459,9 @@ def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 204]: @@ -463,51 +471,42 @@ def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules/{firewallRuleName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.FirewallRuleListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.FirewallRule"]: """Gets a list of firewall rules. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either FirewallRuleListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.FirewallRuleListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either FirewallRule or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.FirewallRule] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.FirewallRuleListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.FirewallRuleListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -515,16 +514,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -540,10 +530,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -553,50 +541,104 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules"} # type: ignore - @distributed_trace + @overload def replace( self, resource_group_name: str, server_name: str, parameters: _models.FirewallRuleList, + *, + content_type: str = "application/json", **kwargs: Any ) -> Optional[_models.FirewallRule]: """Replaces all firewall rules on the server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.FirewallRuleList - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: FirewallRule or None or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.FirewallRule or None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def replace( + self, + resource_group_name: str, + server_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> Optional[_models.FirewallRule]: + """Replaces all firewall rules on the server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: Required. + :type parameters: IO + :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: FirewallRule or None or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.FirewallRule or None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def replace( + self, resource_group_name: str, server_name: str, parameters: Union[_models.FirewallRuleList, IO], **kwargs: Any + ) -> Optional[_models.FirewallRule]: + """Replaces all firewall rules on the server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.FirewallRuleList 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 - :return: FirewallRule, or the result of cls(response) + :return: FirewallRule or None or the result of cls(response) :rtype: ~azure.mgmt.sql.models.FirewallRule or None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.FirewallRule]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.FirewallRule]] - _json = self._serialize.body(parameters, 'FirewallRuleList') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "FirewallRuleList") request = build_replace_request( resource_group_name=resource_group_name, @@ -605,7 +647,8 @@ def replace( api_version=api_version, content_type=content_type, json=_json, - template_url=self.replace.metadata['url'], + content=_content, + template_url=self.replace.metadata["url"], headers=_headers, params=_params, ) @@ -613,10 +656,9 @@ def replace( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -625,12 +667,11 @@ def replace( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('FirewallRule', pipeline_response) + deserialized = self._deserialize("FirewallRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - replace.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules"} # type: ignore - + replace.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/firewallRules"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_geo_backup_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_geo_backup_policies_operations.py index e4bb76f644299..1fd7493fe81f8 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_geo_backup_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_geo_backup_policies_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,140 +24,126 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_create_or_update_request( - subscription_id: str, resource_group_name: str, server_name: str, database_name: str, geo_backup_policy_name: Union[str, "_models.GeoBackupPolicyName"], - *, - json: Optional[_models.GeoBackupPolicy] = None, - content: Any = None, + subscription_id: str, **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', "2014-04-01")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies/{geoBackupPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies/{geoBackupPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "geoBackupPolicyName": _SERIALIZER.url("geo_backup_policy_name", geo_backup_policy_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "geoBackupPolicyName": _SERIALIZER.url("geo_backup_policy_name", geo_backup_policy_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - subscription_id: str, resource_group_name: str, server_name: str, database_name: str, geo_backup_policy_name: Union[str, "_models.GeoBackupPolicyName"], + subscription_id: str, **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', "2014-04-01")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies/{geoBackupPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies/{geoBackupPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "geoBackupPolicyName": _SERIALIZER.url("geo_backup_policy_name", geo_backup_policy_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "geoBackupPolicyName": _SERIALIZER.url("geo_backup_policy_name", geo_backup_policy_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_database_request( - subscription_id: str, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2014-04-01")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class GeoBackupPoliciesOperations: """ @@ -174,8 +164,7 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, @@ -183,53 +172,129 @@ def create_or_update( database_name: str, geo_backup_policy_name: Union[str, "_models.GeoBackupPolicyName"], parameters: _models.GeoBackupPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.GeoBackupPolicy: """Updates a database geo backup policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param geo_backup_policy_name: The name of the geo backup policy. + :param geo_backup_policy_name: The name of the geo backup policy. "Default" Required. :type geo_backup_policy_name: str or ~azure.mgmt.sql.models.GeoBackupPolicyName :param parameters: The required parameters for creating or updating the geo backup policy. + Required. :type parameters: ~azure.mgmt.sql.models.GeoBackupPolicy - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str + :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: GeoBackupPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.GeoBackupPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + geo_backup_policy_name: Union[str, "_models.GeoBackupPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.GeoBackupPolicy: + """Updates a database geo backup policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param geo_backup_policy_name: The name of the geo backup policy. "Default" Required. + :type geo_backup_policy_name: str or ~azure.mgmt.sql.models.GeoBackupPolicyName + :param parameters: The required parameters for creating or updating the geo backup policy. + Required. + :type parameters: IO + :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: GeoBackupPolicy, or the result of cls(response) + :return: GeoBackupPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.GeoBackupPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + geo_backup_policy_name: Union[str, "_models.GeoBackupPolicyName"], + parameters: Union[_models.GeoBackupPolicy, IO], + **kwargs: Any + ) -> _models.GeoBackupPolicy: + """Updates a database geo backup policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param geo_backup_policy_name: The name of the geo backup policy. "Default" Required. + :type geo_backup_policy_name: str or ~azure.mgmt.sql.models.GeoBackupPolicyName + :param parameters: The required parameters for creating or updating the geo backup policy. Is + either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.GeoBackupPolicy 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 + :return: GeoBackupPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.GeoBackupPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.GeoBackupPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.GeoBackupPolicy] - _json = self._serialize.body(parameters, 'GeoBackupPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "GeoBackupPolicy") request = build_create_or_update_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, geo_backup_policy_name=geo_backup_policy_name, + subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -237,10 +302,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -248,18 +312,17 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('GeoBackupPolicy', pipeline_response) + deserialized = self._deserialize("GeoBackupPolicy", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('GeoBackupPolicy', pipeline_response) + deserialized = self._deserialize("GeoBackupPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies/{geoBackupPolicyName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies/{geoBackupPolicyName}"} # type: ignore @distributed_trace def get( @@ -273,42 +336,36 @@ def get( """Gets a geo backup policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param geo_backup_policy_name: The name of the geo backup policy. + :param geo_backup_policy_name: The name of the geo backup policy. "Default" Required. :type geo_backup_policy_name: str or ~azure.mgmt.sql.models.GeoBackupPolicyName - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: GeoBackupPolicy, or the result of cls(response) + :return: GeoBackupPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.GeoBackupPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.GeoBackupPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.GeoBackupPolicy] - request = build_get_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, geo_backup_policy_name=geo_backup_policy_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -316,72 +373,61 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('GeoBackupPolicy', pipeline_response) + deserialized = self._deserialize("GeoBackupPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies/{geoBackupPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies/{geoBackupPolicyName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.GeoBackupPolicyListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.GeoBackupPolicy"]: """Returns a list of geo backup policies. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either GeoBackupPolicyListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.GeoBackupPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either GeoBackupPolicy or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.GeoBackupPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.GeoBackupPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.GeoBackupPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -389,17 +435,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -415,10 +451,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -428,8 +462,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/geoBackupPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_instance_failover_groups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_instance_failover_groups_operations.py index df9563355dc27..00a5a55217417 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_instance_failover_groups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_instance_failover_groups_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,244 +26,203 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( - resource_group_name: str, - location_name: str, - failover_group_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, location_name: str, failover_group_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - resource_group_name: str, - location_name: str, - failover_group_name: str, - subscription_id: str, - *, - json: Optional[_models.InstanceFailoverGroup] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, location_name: str, failover_group_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) - - -def build_delete_request_initial( - resource_group_name: str, - location_name: str, - failover_group_name: str, - subscription_id: str, - **kwargs: Any + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_delete_request( + resource_group_name: str, location_name: str, failover_group_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_location_request( - resource_group_name: str, - location_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, location_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_failover_request_initial( - resource_group_name: str, - location_name: str, - failover_group_name: str, - subscription_id: str, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_failover_request( + resource_group_name: str, location_name: str, failover_group_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/failover") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/failover", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_force_failover_allow_data_loss_request_initial( - resource_group_name: str, - location_name: str, - failover_group_name: str, - subscription_id: str, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_force_failover_allow_data_loss_request( + resource_group_name: str, location_name: str, failover_group_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "failoverGroupName": _SERIALIZER.url("failover_group_name", failover_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class InstanceFailoverGroupsOperations: """ @@ -280,51 +243,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( - self, - resource_group_name: str, - location_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, location_name: str, failover_group_name: str, **kwargs: Any ) -> _models.InstanceFailoverGroup: """Gets a failover group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: InstanceFailoverGroup, or the result of cls(response) + :return: InstanceFailoverGroup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.InstanceFailoverGroup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstanceFailoverGroup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstanceFailoverGroup] - request = build_get_request( resource_group_name=resource_group_name, location_name=location_name, failover_group_name=failover_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -332,49 +284,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('InstanceFailoverGroup', pipeline_response) + deserialized = self._deserialize("InstanceFailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, location_name: str, failover_group_name: str, - parameters: _models.InstanceFailoverGroup, + parameters: Union[_models.InstanceFailoverGroup, IO], **kwargs: Any ) -> Optional[_models.InstanceFailoverGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.InstanceFailoverGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.InstanceFailoverGroup]] - _json = self._serialize.body(parameters, 'InstanceFailoverGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "InstanceFailoverGroup") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, location_name=location_name, failover_group_name=failover_group_name, @@ -382,7 +336,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -390,10 +345,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -402,42 +356,82 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('InstanceFailoverGroup', pipeline_response) + deserialized = self._deserialize("InstanceFailoverGroup", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('InstanceFailoverGroup', pipeline_response) + deserialized = self._deserialize("InstanceFailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, location_name: str, failover_group_name: str, parameters: _models.InstanceFailoverGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.InstanceFailoverGroup]: """Creates or updates a failover group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :param parameters: The failover group parameters. + :param parameters: The failover group parameters. Required. :type parameters: ~azure.mgmt.sql.models.InstanceFailoverGroup - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 InstanceFailoverGroup or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.InstanceFailoverGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + location_name: str, + failover_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.InstanceFailoverGroup]: + """Creates or updates a failover group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param location_name: The name of the region where the resource is located. Required. + :type location_name: str + :param failover_group_name: The name of the failover group. Required. + :type failover_group_name: str + :param parameters: The failover group parameters. Required. + :type parameters: IO + :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 @@ -449,20 +443,55 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either InstanceFailoverGroup or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.InstanceFailoverGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + location_name: str, + failover_group_name: str, + parameters: Union[_models.InstanceFailoverGroup, IO], + **kwargs: Any + ) -> LROPoller[_models.InstanceFailoverGroup]: + """Creates or updates a failover group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param location_name: The name of the region where the resource is located. Required. + :type location_name: str + :param failover_group_name: The name of the failover group. Required. + :type failover_group_name: str + :param parameters: The failover group parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.InstanceFailoverGroup 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. + :return: An instance of LROPoller that returns either InstanceFailoverGroup or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.InstanceFailoverGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstanceFailoverGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstanceFailoverGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -471,66 +500,55 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('InstanceFailoverGroup', pipeline_response) + deserialized = self._deserialize("InstanceFailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - location_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, location_name: str, failover_group_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, location_name=location_name, failover_group_name=failover_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -538,10 +556,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -551,29 +568,21 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - location_name: str, - failover_group_name: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, location_name: str, failover_group_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes a failover group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -584,99 +593,85 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, location_name=location_name, failover_group_name=failover_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}"} # type: ignore @distributed_trace def list_by_location( - self, - resource_group_name: str, - location_name: str, - **kwargs: Any - ) -> Iterable[_models.InstanceFailoverGroupListResult]: + self, resource_group_name: str, location_name: str, **kwargs: Any + ) -> Iterable["_models.InstanceFailoverGroup"]: """Lists the failover groups in a location. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either InstanceFailoverGroupListResult or the result of + :return: An iterator like instance of either InstanceFailoverGroup or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.InstanceFailoverGroupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.InstanceFailoverGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstanceFailoverGroupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstanceFailoverGroupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_location_request( resource_group_name=resource_group_name, location_name=location_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_location.metadata['url'], + template_url=self.list_by_location.metadata["url"], headers=_headers, params=_params, ) @@ -684,16 +679,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_location_request( - resource_group_name=resource_group_name, - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -709,10 +695,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -722,38 +706,29 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups"} # type: ignore + list_by_location.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups"} # type: ignore def _failover_initial( - self, - resource_group_name: str, - location_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, location_name: str, failover_group_name: str, **kwargs: Any ) -> Optional[_models.InstanceFailoverGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.InstanceFailoverGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.InstanceFailoverGroup]] - - request = build_failover_request_initial( + request = build_failover_request( resource_group_name=resource_group_name, location_name=location_name, failover_group_name=failover_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._failover_initial.metadata['url'], + template_url=self._failover_initial.metadata["url"], headers=_headers, params=_params, ) @@ -761,10 +736,9 @@ def _failover_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -773,36 +747,28 @@ def _failover_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('InstanceFailoverGroup', pipeline_response) + deserialized = self._deserialize("InstanceFailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _failover_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/failover"} # type: ignore - + _failover_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/failover"} # type: ignore @distributed_trace def begin_failover( - self, - resource_group_name: str, - location_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, location_name: str, failover_group_name: str, **kwargs: Any ) -> LROPoller[_models.InstanceFailoverGroup]: """Fails over from the current primary managed instance to this managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -814,85 +780,71 @@ def begin_failover( :return: An instance of LROPoller that returns either InstanceFailoverGroup or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.InstanceFailoverGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstanceFailoverGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstanceFailoverGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._failover_initial( # type: ignore resource_group_name=resource_group_name, location_name=location_name, failover_group_name=failover_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('InstanceFailoverGroup', pipeline_response) + deserialized = self._deserialize("InstanceFailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_failover.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/failover"} # type: ignore + begin_failover.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/failover"} # type: ignore def _force_failover_allow_data_loss_initial( - self, - resource_group_name: str, - location_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, location_name: str, failover_group_name: str, **kwargs: Any ) -> Optional[_models.InstanceFailoverGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.InstanceFailoverGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.InstanceFailoverGroup]] - - request = build_force_failover_allow_data_loss_request_initial( + request = build_force_failover_allow_data_loss_request( resource_group_name=resource_group_name, location_name=location_name, failover_group_name=failover_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._force_failover_allow_data_loss_initial.metadata['url'], + template_url=self._force_failover_allow_data_loss_initial.metadata["url"], headers=_headers, params=_params, ) @@ -900,10 +852,9 @@ def _force_failover_allow_data_loss_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -912,37 +863,29 @@ def _force_failover_allow_data_loss_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('InstanceFailoverGroup', pipeline_response) + deserialized = self._deserialize("InstanceFailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _force_failover_allow_data_loss_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss"} # type: ignore - + _force_failover_allow_data_loss_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss"} # type: ignore @distributed_trace def begin_force_failover_allow_data_loss( - self, - resource_group_name: str, - location_name: str, - failover_group_name: str, - **kwargs: Any + self, resource_group_name: str, location_name: str, failover_group_name: str, **kwargs: Any ) -> LROPoller[_models.InstanceFailoverGroup]: """Fails over from the current primary managed instance to this managed instance. This operation might result in data loss. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param failover_group_name: The name of the failover group. + :param failover_group_name: The name of the failover group. Required. :type failover_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -954,55 +897,48 @@ def begin_force_failover_allow_data_loss( :return: An instance of LROPoller that returns either InstanceFailoverGroup or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.InstanceFailoverGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstanceFailoverGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstanceFailoverGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._force_failover_allow_data_loss_initial( # type: ignore resource_group_name=resource_group_name, location_name=location_name, failover_group_name=failover_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('InstanceFailoverGroup', pipeline_response) + deserialized = self._deserialize("InstanceFailoverGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_force_failover_allow_data_loss.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss"} # type: ignore + begin_force_failover_allow_data_loss.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/instanceFailoverGroups/{failoverGroupName}/forceFailoverAllowDataLoss"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_instance_pools_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_instance_pools_operations.py index 93b1e3a00cb08..da46b6581497f 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_instance_pools_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_instance_pools_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,236 +26,191 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( - resource_group_name: str, - instance_pool_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, instance_pool_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "instancePoolName": _SERIALIZER.url("instance_pool_name", instance_pool_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "instancePoolName": _SERIALIZER.url("instance_pool_name", instance_pool_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - resource_group_name: str, - instance_pool_name: str, - subscription_id: str, - *, - json: Optional[_models.InstancePool] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, instance_pool_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "instancePoolName": _SERIALIZER.url("instance_pool_name", instance_pool_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "instancePoolName": _SERIALIZER.url("instance_pool_name", instance_pool_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) - - -def build_delete_request_initial( - resource_group_name: str, - instance_pool_name: str, - subscription_id: str, - **kwargs: Any + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_delete_request( + resource_group_name: str, instance_pool_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "instancePoolName": _SERIALIZER.url("instance_pool_name", instance_pool_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "instancePoolName": _SERIALIZER.url("instance_pool_name", instance_pool_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') - - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) - - -def build_update_request_initial( - resource_group_name: str, - instance_pool_name: str, - subscription_id: str, - *, - json: Optional[_models.InstancePoolUpdate] = None, - content: Any = None, - **kwargs: Any + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) + + +def build_update_request( + resource_group_name: str, instance_pool_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "instancePoolName": _SERIALIZER.url("instance_pool_name", instance_pool_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "instancePoolName": _SERIALIZER.url("instance_pool_name", instance_pool_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) - - -def build_list_by_resource_group_request( - resource_group_name: str, - subscription_id: str, - **kwargs: Any -) -> HttpRequest: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_list_by_resource_group_request(resource_group_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_list_request( - subscription_id: str, - **kwargs: Any -) -> HttpRequest: +def build_list_request(subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/instancePools") path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class InstancePoolsOperations: """ @@ -272,47 +231,35 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace - def get( - self, - resource_group_name: str, - instance_pool_name: str, - **kwargs: Any - ) -> _models.InstancePool: + def get(self, resource_group_name: str, instance_pool_name: str, **kwargs: Any) -> _models.InstancePool: """Gets an instance pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param instance_pool_name: The name of the instance pool to be retrieved. + :param instance_pool_name: The name of the instance pool to be retrieved. Required. :type instance_pool_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: InstancePool, or the result of cls(response) + :return: InstancePool or the result of cls(response) :rtype: ~azure.mgmt.sql.models.InstancePool - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstancePool] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstancePool] - request = build_get_request( resource_group_name=resource_group_name, instance_pool_name=instance_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -320,55 +267,58 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('InstancePool', pipeline_response) + deserialized = self._deserialize("InstancePool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, instance_pool_name: str, - parameters: _models.InstancePool, + parameters: Union[_models.InstancePool, IO], **kwargs: Any ) -> Optional[_models.InstancePool]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.InstancePool]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.InstancePool]] - _json = self._serialize.body(parameters, 'InstancePool') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "InstancePool") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, instance_pool_name=instance_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -376,10 +326,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -388,39 +337,76 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('InstancePool', pipeline_response) + deserialized = self._deserialize("InstancePool", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('InstancePool', pipeline_response) + deserialized = self._deserialize("InstancePool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, instance_pool_name: str, parameters: _models.InstancePool, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.InstancePool]: """Creates or updates an instance pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param instance_pool_name: The name of the instance pool to be created or updated. + :param instance_pool_name: The name of the instance pool to be created or updated. Required. :type instance_pool_name: str - :param parameters: The requested instance pool resource state. + :param parameters: The requested instance pool resource state. Required. :type parameters: ~azure.mgmt.sql.models.InstancePool - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 InstancePool or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.InstancePool] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + instance_pool_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.InstancePool]: + """Creates or updates an instance pool. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param instance_pool_name: The name of the instance pool to be created or updated. Required. + :type instance_pool_name: str + :param parameters: The requested instance pool resource state. Required. + :type parameters: IO + :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 @@ -432,20 +418,52 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either InstancePool or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.InstancePool] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + instance_pool_name: str, + parameters: Union[_models.InstancePool, IO], + **kwargs: Any + ) -> LROPoller[_models.InstancePool]: + """Creates or updates an instance pool. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param instance_pool_name: The name of the instance pool to be created or updated. Required. + :type instance_pool_name: str + :param parameters: The requested instance pool resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.InstancePool 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. + :return: An instance of LROPoller that returns either InstancePool or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.InstancePool] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstancePool] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstancePool] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -453,64 +471,54 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('InstancePool', pipeline_response) + deserialized = self._deserialize("InstancePool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/instancePools/{instancePoolName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - instance_pool_name: str, - **kwargs: Any + self, resource_group_name: str, instance_pool_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, instance_pool_name=instance_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -518,10 +526,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -531,26 +538,17 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - instance_pool_name: str, - **kwargs: Any - ) -> LROPoller[None]: + def begin_delete(self, resource_group_name: str, instance_pool_name: str, **kwargs: Any) -> LROPoller[None]: """Deletes an instance pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param instance_pool_name: The name of the instance pool to be deleted. + :param instance_pool_name: The name of the instance pool to be deleted. Required. :type instance_pool_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -561,85 +559,83 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, instance_pool_name=instance_pool_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/instancePools/{instancePoolName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore def _update_initial( self, resource_group_name: str, instance_pool_name: str, - parameters: _models.InstancePoolUpdate, + parameters: Union[_models.InstancePoolUpdate, IO], **kwargs: Any ) -> Optional[_models.InstancePool]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.InstancePool]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.InstancePool]] - _json = self._serialize.body(parameters, 'InstancePoolUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "InstancePoolUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, instance_pool_name=instance_pool_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -647,10 +643,9 @@ def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -659,36 +654,108 @@ def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('InstancePool', pipeline_response) + deserialized = self._deserialize("InstancePool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore - + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore - @distributed_trace + @overload def begin_update( self, resource_group_name: str, instance_pool_name: str, parameters: _models.InstancePoolUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.InstancePool]: """Updates an instance pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param instance_pool_name: The name of the instance pool to be updated. + :param instance_pool_name: The name of the instance pool to be updated. Required. :type instance_pool_name: str - :param parameters: The requested instance pool resource state. + :param parameters: The requested instance pool resource state. Required. :type parameters: ~azure.mgmt.sql.models.InstancePoolUpdate - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 InstancePool or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.InstancePool] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_update( + self, + resource_group_name: str, + instance_pool_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.InstancePool]: + """Updates an instance pool. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param instance_pool_name: The name of the instance pool to be updated. Required. + :type instance_pool_name: str + :param parameters: The requested instance pool resource state. Required. + :type parameters: IO + :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 InstancePool or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.InstancePool] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_update( + self, + resource_group_name: str, + instance_pool_name: str, + parameters: Union[_models.InstancePoolUpdate, IO], + **kwargs: Any + ) -> LROPoller[_models.InstancePool]: + """Updates an instance pool. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param instance_pool_name: The name of the instance pool to be updated. Required. + :type instance_pool_name: str + :param parameters: The requested instance pool resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.InstancePoolUpdate 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 @@ -700,20 +767,17 @@ def begin_update( :return: An instance of LROPoller that returns either InstancePool or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.InstancePool] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstancePool] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstancePool] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -721,78 +785,65 @@ def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('InstancePool', pipeline_response) + deserialized = self._deserialize("InstancePool", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}"} # type: ignore @distributed_trace - def list_by_resource_group( - self, - resource_group_name: str, - **kwargs: Any - ) -> Iterable[_models.InstancePoolListResult]: + def list_by_resource_group(self, resource_group_name: str, **kwargs: Any) -> Iterable["_models.InstancePool"]: """Gets a list of instance pools in the resource group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either InstancePoolListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.InstancePoolListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either InstancePool or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.InstancePool] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstancePoolListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstancePoolListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_request( resource_group_name=resource_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_resource_group.metadata['url'], + template_url=self.list_by_resource_group.metadata["url"], headers=_headers, params=_params, ) @@ -800,15 +851,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -824,10 +867,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -837,45 +878,35 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools"} # type: ignore + list_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools"} # type: ignore @distributed_trace - def list( - self, - **kwargs: Any - ) -> Iterable[_models.InstancePoolListResult]: + def list(self, **kwargs: Any) -> Iterable["_models.InstancePool"]: """Gets a list of all instance pools in the subscription. - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either InstancePoolListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.InstancePoolListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either InstancePool or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.InstancePool] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.InstancePoolListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.InstancePoolListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_request( subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list.metadata['url'], + template_url=self.list.metadata["url"], headers=_headers, params=_params, ) @@ -883,14 +914,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_request( - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -906,10 +930,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -919,8 +941,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/instancePools"} # type: ignore + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/instancePools"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_ipv6_firewall_rules_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_ipv6_firewall_rules_operations.py index 4ce6c08da93f3..3dcfb4efbc2ba 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_ipv6_firewall_rules_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_ipv6_firewall_rules_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,166 +24,139 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - server_name: str, - firewall_rule_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, firewall_rule_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "firewallRuleName": _SERIALIZER.url("firewall_rule_name", firewall_rule_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "firewallRuleName": _SERIALIZER.url("firewall_rule_name", firewall_rule_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( - resource_group_name: str, - server_name: str, - firewall_rule_name: str, - subscription_id: str, - *, - json: Optional[_models.IPv6FirewallRule] = None, - content: Any = None, - **kwargs: Any + resource_group_name: str, server_name: str, firewall_rule_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "firewallRuleName": _SERIALIZER.url("firewall_rule_name", firewall_rule_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "firewallRuleName": _SERIALIZER.url("firewall_rule_name", firewall_rule_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_delete_request( - resource_group_name: str, - server_name: str, - firewall_rule_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, firewall_rule_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "firewallRuleName": _SERIALIZER.url("firewall_rule_name", firewall_rule_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "firewallRuleName": _SERIALIZER.url("firewall_rule_name", firewall_rule_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) class IPv6FirewallRulesOperations: """ @@ -200,49 +177,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.IPv6FirewallRuleListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.IPv6FirewallRule"]: """Gets a list of IPv6 firewall rules. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either IPv6FirewallRuleListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.IPv6FirewallRuleListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either IPv6FirewallRule or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.IPv6FirewallRule] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.IPv6FirewallRuleListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.IPv6FirewallRuleListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -250,16 +218,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -275,10 +234,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -288,56 +245,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - firewall_rule_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, firewall_rule_name: str, **kwargs: Any ) -> _models.IPv6FirewallRule: """Gets an IPv6 firewall rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param firewall_rule_name: The name of the firewall rule. + :param firewall_rule_name: The name of the firewall rule. Required. :type firewall_rule_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: IPv6FirewallRule, or the result of cls(response) + :return: IPv6FirewallRule or the result of cls(response) :rtype: ~azure.mgmt.sql.models.IPv6FirewallRule - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.IPv6FirewallRule] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.IPv6FirewallRule] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, firewall_rule_name=firewall_rule_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -345,67 +290,134 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('IPv6FirewallRule', pipeline_response) + deserialized = self._deserialize("IPv6FirewallRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, server_name: str, firewall_rule_name: str, parameters: _models.IPv6FirewallRule, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.IPv6FirewallRule: """Creates or updates an IPv6 firewall rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param firewall_rule_name: The name of the firewall rule. + :param firewall_rule_name: The name of the firewall rule. Required. :type firewall_rule_name: str :param parameters: The required parameters for creating or updating an IPv6 firewall rule. + Required. :type parameters: ~azure.mgmt.sql.models.IPv6FirewallRule - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: IPv6FirewallRule or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.IPv6FirewallRule + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + firewall_rule_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.IPv6FirewallRule: + """Creates or updates an IPv6 firewall rule. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param firewall_rule_name: The name of the firewall rule. Required. + :type firewall_rule_name: str + :param parameters: The required parameters for creating or updating an IPv6 firewall rule. + Required. + :type parameters: IO + :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: IPv6FirewallRule, or the result of cls(response) + :return: IPv6FirewallRule or the result of cls(response) :rtype: ~azure.mgmt.sql.models.IPv6FirewallRule - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + firewall_rule_name: str, + parameters: Union[_models.IPv6FirewallRule, IO], + **kwargs: Any + ) -> _models.IPv6FirewallRule: + """Creates or updates an IPv6 firewall rule. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param firewall_rule_name: The name of the firewall rule. Required. + :type firewall_rule_name: str + :param parameters: The required parameters for creating or updating an IPv6 firewall rule. Is + either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.IPv6FirewallRule 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 + :return: IPv6FirewallRule or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.IPv6FirewallRule + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.IPv6FirewallRule] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.IPv6FirewallRule] - _json = self._serialize.body(parameters, 'IPv6FirewallRule') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "IPv6FirewallRule") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -415,7 +427,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -423,10 +436,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -434,63 +446,52 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('IPv6FirewallRule', pipeline_response) + deserialized = self._deserialize("IPv6FirewallRule", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('IPv6FirewallRule', pipeline_response) + deserialized = self._deserialize("IPv6FirewallRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}"} # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - firewall_rule_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, firewall_rule_name: str, **kwargs: Any ) -> None: """Deletes an IPv6 firewall rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param firewall_rule_name: The name of the firewall rule. + :param firewall_rule_name: The name of the firewall rule. Required. :type firewall_rule_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, firewall_rule_name=firewall_rule_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -498,10 +499,9 @@ def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 204]: @@ -511,5 +511,4 @@ def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/ipv6FirewallRules/{firewallRuleName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_agents_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_agents_operations.py index 654aa03ecab80..69e405b317249 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_agents_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_agents_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,213 +26,174 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - server_name: str, - job_agent_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, job_agent_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - resource_group_name: str, - server_name: str, - job_agent_name: str, - subscription_id: str, - *, - json: Optional[_models.JobAgent] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, server_name: str, job_agent_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) - - -def build_delete_request_initial( - resource_group_name: str, - server_name: str, - job_agent_name: str, - subscription_id: str, - **kwargs: Any + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_delete_request( + resource_group_name: str, server_name: str, job_agent_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') - - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) - - -def build_update_request_initial( - resource_group_name: str, - server_name: str, - job_agent_name: str, - subscription_id: str, - *, - json: Optional[_models.JobAgentUpdate] = None, - content: Any = None, - **kwargs: Any + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) + + +def build_update_request( + resource_group_name: str, server_name: str, job_agent_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) + class JobAgentsOperations: """ @@ -249,48 +214,38 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace - def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.JobAgentListResult]: + def list_by_server(self, resource_group_name: str, server_name: str, **kwargs: Any) -> Iterable["_models.JobAgent"]: """Gets a list of job agents in a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobAgentListResult or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobAgentListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobAgent or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobAgent] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobAgentListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobAgentListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -298,16 +253,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -323,10 +269,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -336,56 +280,42 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents"} # type: ignore @distributed_trace - def get( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - **kwargs: Any - ) -> _models.JobAgent: + def get(self, resource_group_name: str, server_name: str, job_agent_name: str, **kwargs: Any) -> _models.JobAgent: """Gets a job agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent to be retrieved. + :param job_agent_name: The name of the job agent to be retrieved. Required. :type job_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobAgent, or the result of cls(response) + :return: JobAgent or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobAgent - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobAgent] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobAgent] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -393,49 +323,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobAgent', pipeline_response) + deserialized = self._deserialize("JobAgent", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, job_agent_name: str, - parameters: _models.JobAgent, + parameters: Union[_models.JobAgent, IO], **kwargs: Any ) -> Optional[_models.JobAgent]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.JobAgent]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.JobAgent]] - _json = self._serialize.body(parameters, 'JobAgent') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "JobAgent") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, @@ -443,7 +375,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -451,10 +384,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -463,42 +395,43 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('JobAgent', pipeline_response) + deserialized = self._deserialize("JobAgent", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('JobAgent', pipeline_response) + deserialized = self._deserialize("JobAgent", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, job_agent_name: str, parameters: _models.JobAgent, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.JobAgent]: """Creates or updates a job agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent to be created or updated. + :param job_agent_name: The name of the job agent to be created or updated. Required. :type job_agent_name: str - :param parameters: The requested job agent resource state. + :param parameters: The requested job agent resource state. Required. :type parameters: ~azure.mgmt.sql.models.JobAgent - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -509,20 +442,92 @@ def begin_create_or_update( Retry-After header is present. :return: An instance of LROPoller that returns either JobAgent or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.JobAgent] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.JobAgent]: + """Creates or updates a job agent. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent to be created or updated. Required. + :type job_agent_name: str + :param parameters: The requested job agent resource state. Required. + :type parameters: IO + :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 JobAgent or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.JobAgent] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + parameters: Union[_models.JobAgent, IO], + **kwargs: Any + ) -> LROPoller[_models.JobAgent]: + """Creates or updates a job agent. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent to be created or updated. Required. + :type job_agent_name: str + :param parameters: The requested job agent resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.JobAgent 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. + :return: An instance of LROPoller that returns either JobAgent or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.JobAgent] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobAgent] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobAgent] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -531,66 +536,55 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('JobAgent', pipeline_response) + deserialized = self._deserialize("JobAgent", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -598,10 +592,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -611,29 +604,21 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, server_name: str, job_agent_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes a job agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent to be deleted. + :param job_agent_name: The name of the job agent to be deleted. Required. :type job_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -644,80 +629,77 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore def _update_initial( self, resource_group_name: str, server_name: str, job_agent_name: str, - parameters: _models.JobAgentUpdate, + parameters: Union[_models.JobAgentUpdate, IO], **kwargs: Any ) -> Optional[_models.JobAgent]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.JobAgent]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.JobAgent]] - _json = self._serialize.body(parameters, 'JobAgentUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "JobAgentUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, @@ -725,7 +707,8 @@ def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -733,10 +716,9 @@ def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -745,39 +727,40 @@ def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('JobAgent', pipeline_response) + deserialized = self._deserialize("JobAgent", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore - + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore - @distributed_trace + @overload def begin_update( self, resource_group_name: str, server_name: str, job_agent_name: str, parameters: _models.JobAgentUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.JobAgent]: """Updates a job agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent to be updated. + :param job_agent_name: The name of the job agent to be updated. Required. :type job_agent_name: str - :param parameters: The update to the job agent. + :param parameters: The update to the job agent. Required. :type parameters: ~azure.mgmt.sql.models.JobAgentUpdate - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -788,20 +771,91 @@ def begin_update( Retry-After header is present. :return: An instance of LROPoller that returns either JobAgent or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.JobAgent] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.JobAgent]: + """Updates a job agent. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent to be updated. Required. + :type job_agent_name: str + :param parameters: The update to the job agent. Required. + :type parameters: IO + :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 JobAgent or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.JobAgent] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + parameters: Union[_models.JobAgentUpdate, IO], + **kwargs: Any + ) -> LROPoller[_models.JobAgent]: + """Updates a job agent. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent to be updated. Required. + :type job_agent_name: str + :param parameters: The update to the job agent. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.JobAgentUpdate 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. + :return: An instance of LROPoller that returns either JobAgent or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.JobAgent] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobAgent] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobAgent] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -810,36 +864,32 @@ def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('JobAgent', pipeline_response) + deserialized = self._deserialize("JobAgent", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_credentials_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_credentials_operations.py index 588d43b04d081..2ec2420c86351 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_credentials_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_credentials_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,50 +24,46 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_agent_request( - resource_group_name: str, - server_name: str, - job_agent_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, job_agent_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -77,34 +77,31 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "credentialName": _SERIALIZER.url("credential_name", credential_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "credentialName": _SERIALIZER.url("credential_name", credential_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( @@ -113,47 +110,39 @@ def build_create_or_update_request( job_agent_name: str, credential_name: str, subscription_id: str, - *, - json: Optional[_models.JobCredential] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "credentialName": _SERIALIZER.url("credential_name", credential_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "credentialName": _SERIALIZER.url("credential_name", credential_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_delete_request( @@ -166,28 +155,27 @@ def build_delete_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "credentialName": _SERIALIZER.url("credential_name", credential_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "credentialName": _SERIALIZER.url("credential_name", credential_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) class JobCredentialsOperations: """ @@ -208,53 +196,43 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_agent( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - **kwargs: Any - ) -> Iterable[_models.JobCredentialListResult]: + self, resource_group_name: str, server_name: str, job_agent_name: str, **kwargs: Any + ) -> Iterable["_models.JobCredential"]: """Gets a list of jobs credentials. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobCredentialListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobCredentialListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobCredential or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobCredential] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobCredentialListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobCredentialListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_agent_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_agent.metadata['url'], + template_url=self.list_by_agent.metadata["url"], headers=_headers, params=_params, ) @@ -262,17 +240,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_agent_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -288,10 +256,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -301,52 +267,39 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_agent.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials"} # type: ignore + list_by_agent.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - credential_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, credential_name: str, **kwargs: Any ) -> _models.JobCredential: """Gets a jobs credential. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param credential_name: The name of the credential. + :param credential_name: The name of the credential. Required. :type credential_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobCredential, or the result of cls(response) + :return: JobCredential or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobCredential - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobCredential] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobCredential] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -354,7 +307,7 @@ def get( credential_name=credential_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -362,27 +315,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobCredential', pipeline_response) + deserialized = self._deserialize("JobCredential", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, @@ -390,42 +341,115 @@ def create_or_update( job_agent_name: str, credential_name: str, parameters: _models.JobCredential, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.JobCredential: """Creates or updates a job credential. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param credential_name: The name of the credential. + :param credential_name: The name of the credential. Required. :type credential_name: str - :param parameters: The requested job credential state. + :param parameters: The requested job credential state. Required. :type parameters: ~azure.mgmt.sql.models.JobCredential - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: JobCredential or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.JobCredential + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + credential_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.JobCredential: + """Creates or updates a job credential. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent. Required. + :type job_agent_name: str + :param credential_name: The name of the credential. Required. + :type credential_name: str + :param parameters: The requested job credential state. Required. + :type parameters: IO + :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: JobCredential, or the result of cls(response) + :return: JobCredential or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobCredential - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + credential_name: str, + parameters: Union[_models.JobCredential, IO], + **kwargs: Any + ) -> _models.JobCredential: + """Creates or updates a job credential. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent. Required. + :type job_agent_name: str + :param credential_name: The name of the credential. Required. + :type credential_name: str + :param parameters: The requested job credential state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.JobCredential 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 + :return: JobCredential or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.JobCredential + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobCredential] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobCredential] - _json = self._serialize.body(parameters, 'JobCredential') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "JobCredential") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -436,7 +460,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -444,10 +469,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -455,59 +479,47 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('JobCredential', pipeline_response) + deserialized = self._deserialize("JobCredential", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('JobCredential', pipeline_response) + deserialized = self._deserialize("JobCredential", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}"} # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - credential_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, credential_name: str, **kwargs: Any ) -> None: """Deletes a job credential. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param credential_name: The name of the credential. + :param credential_name: The name of the credential. Required. :type credential_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -515,7 +527,7 @@ def delete( # pylint: disable=inconsistent-return-statements credential_name=credential_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -523,10 +535,9 @@ def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 204]: @@ -536,5 +547,4 @@ def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/credentials/{credentialName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_executions_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_executions_operations.py index 4742a4d57be5c..d35a06c8b8d66 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_executions_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_executions_operations.py @@ -9,9 +9,13 @@ import datetime from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -23,13 +27,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_agent_request( resource_group_name: str, server_name: str, @@ -48,47 +55,44 @@ def build_list_by_agent_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/executions") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/executions", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if create_time_min is not None: - _params['createTimeMin'] = _SERIALIZER.query("create_time_min", create_time_min, 'iso-8601') + _params["createTimeMin"] = _SERIALIZER.query("create_time_min", create_time_min, "iso-8601") if create_time_max is not None: - _params['createTimeMax'] = _SERIALIZER.query("create_time_max", create_time_max, 'iso-8601') + _params["createTimeMax"] = _SERIALIZER.query("create_time_max", create_time_max, "iso-8601") if end_time_min is not None: - _params['endTimeMin'] = _SERIALIZER.query("end_time_min", end_time_min, 'iso-8601') + _params["endTimeMin"] = _SERIALIZER.query("end_time_min", end_time_min, "iso-8601") if end_time_max is not None: - _params['endTimeMax'] = _SERIALIZER.query("end_time_max", end_time_max, 'iso-8601') + _params["endTimeMax"] = _SERIALIZER.query("end_time_max", end_time_max, "iso-8601") if is_active is not None: - _params['isActive'] = _SERIALIZER.query("is_active", is_active, 'bool') + _params["isActive"] = _SERIALIZER.query("is_active", is_active, "bool") if skip is not None: - _params['$skip'] = _SERIALIZER.query("skip", skip, 'int') + _params["$skip"] = _SERIALIZER.query("skip", skip, "int") if top is not None: - _params['$top'] = _SERIALIZER.query("top", top, 'int') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$top"] = _SERIALIZER.query("top", top, "int") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_cancel_request( @@ -102,70 +106,60 @@ def build_cancel_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/cancel") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/cancel", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "jobExecutionId": _SERIALIZER.url("job_execution_id", job_execution_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "jobExecutionId": _SERIALIZER.url("job_execution_id", job_execution_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) -def build_create_request_initial( - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - subscription_id: str, - **kwargs: Any +def build_create_request( + resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/start") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/start", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_job_request( @@ -187,48 +181,45 @@ def build_list_by_job_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if create_time_min is not None: - _params['createTimeMin'] = _SERIALIZER.query("create_time_min", create_time_min, 'iso-8601') + _params["createTimeMin"] = _SERIALIZER.query("create_time_min", create_time_min, "iso-8601") if create_time_max is not None: - _params['createTimeMax'] = _SERIALIZER.query("create_time_max", create_time_max, 'iso-8601') + _params["createTimeMax"] = _SERIALIZER.query("create_time_max", create_time_max, "iso-8601") if end_time_min is not None: - _params['endTimeMin'] = _SERIALIZER.query("end_time_min", end_time_min, 'iso-8601') + _params["endTimeMin"] = _SERIALIZER.query("end_time_min", end_time_min, "iso-8601") if end_time_max is not None: - _params['endTimeMax'] = _SERIALIZER.query("end_time_max", end_time_max, 'iso-8601') + _params["endTimeMax"] = _SERIALIZER.query("end_time_max", end_time_max, "iso-8601") if is_active is not None: - _params['isActive'] = _SERIALIZER.query("is_active", is_active, 'bool') + _params["isActive"] = _SERIALIZER.query("is_active", is_active, "bool") if skip is not None: - _params['$skip'] = _SERIALIZER.query("skip", skip, 'int') + _params["$skip"] = _SERIALIZER.query("skip", skip, "int") if top is not None: - _params['$top'] = _SERIALIZER.query("top", top, 'int') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$top"] = _SERIALIZER.query("top", top, "int") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -243,38 +234,35 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "jobExecutionId": _SERIALIZER.url("job_execution_id", job_execution_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "jobExecutionId": _SERIALIZER.url("job_execution_id", job_execution_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, server_name: str, job_agent_name: str, @@ -286,35 +274,33 @@ def build_create_or_update_request_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "jobExecutionId": _SERIALIZER.url("job_execution_id", job_execution_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "jobExecutionId": _SERIALIZER.url("job_execution_id", job_execution_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class JobExecutionsOperations: """ @@ -335,7 +321,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_agent( self, @@ -350,15 +335,15 @@ def list_by_agent( skip: Optional[int] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable[_models.JobExecutionListResult]: + ) -> Iterable["_models.JobExecution"]: """Lists all executions in a job agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str :param create_time_min: If specified, only job executions created at or after the specified time are included. Default value is None. @@ -379,34 +364,28 @@ def list_by_agent( :type skip: int :param top: The number of elements to return from the collection. Default value is None. :type top: int - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobExecutionListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobExecutionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobExecution or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobExecution] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecutionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecutionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_agent_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, subscription_id=self._config.subscription_id, - api_version=api_version, create_time_min=create_time_min, create_time_max=create_time_max, end_time_min=end_time_min, @@ -414,7 +393,8 @@ def prepare_request(next_link=None): is_active=is_active, skip=skip, top=top, - template_url=self.list_by_agent.metadata['url'], + api_version=api_version, + template_url=self.list_by_agent.metadata["url"], headers=_headers, params=_params, ) @@ -422,24 +402,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_agent_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - create_time_min=create_time_min, - create_time_max=create_time_max, - end_time_min=end_time_min, - end_time_max=end_time_max, - is_active=is_active, - skip=skip, - top=top, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -455,10 +418,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -468,11 +429,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_agent.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/executions"} # type: ignore + list_by_agent.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/executions"} # type: ignore @distributed_trace def cancel( # pylint: disable=inconsistent-return-statements @@ -487,36 +446,30 @@ def cancel( # pylint: disable=inconsistent-return-statements """Requests cancellation of a job execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job. + :param job_name: The name of the job. Required. :type job_name: str - :param job_execution_id: The id of the job execution to cancel. + :param job_execution_id: The id of the job execution to cancel. Required. :type job_execution_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_cancel_request( resource_group_name=resource_group_name, server_name=server_name, @@ -525,7 +478,7 @@ def cancel( # pylint: disable=inconsistent-return-statements job_execution_id=job_execution_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.cancel.metadata['url'], + template_url=self.cancel.metadata["url"], headers=_headers, params=_params, ) @@ -533,10 +486,9 @@ def cancel( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -546,37 +498,28 @@ def cancel( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - cancel.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/cancel"} # type: ignore - + cancel.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/cancel"} # type: ignore def _create_initial( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, **kwargs: Any ) -> Optional[_models.JobExecution]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.JobExecution]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.JobExecution]] - - request = build_create_request_initial( + request = build_create_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, job_name=job_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._create_initial.metadata['url'], + template_url=self._create_initial.metadata["url"], headers=_headers, params=_params, ) @@ -584,10 +527,9 @@ def _create_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -596,39 +538,30 @@ def _create_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('JobExecution', pipeline_response) + deserialized = self._deserialize("JobExecution", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/start"} # type: ignore - + _create_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/start"} # type: ignore @distributed_trace def begin_create( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, **kwargs: Any ) -> LROPoller[_models.JobExecution]: """Starts an elastic job execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -640,19 +573,16 @@ def begin_create( :return: An instance of LROPoller that returns either JobExecution or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.JobExecution] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecution] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecution] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_initial( # type: ignore resource_group_name=resource_group_name, @@ -660,39 +590,35 @@ def begin_create( job_agent_name=job_agent_name, job_name=job_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('JobExecution', pipeline_response) + deserialized = self._deserialize("JobExecution", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_create.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/start"} # type: ignore + begin_create.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/start"} # type: ignore @distributed_trace def list_by_job( @@ -709,17 +635,17 @@ def list_by_job( skip: Optional[int] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable[_models.JobExecutionListResult]: + ) -> Iterable["_models.JobExecution"]: """Lists a job's executions. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str :param create_time_min: If specified, only job executions created at or after the specified time are included. Default value is None. @@ -740,35 +666,29 @@ def list_by_job( :type skip: int :param top: The number of elements to return from the collection. Default value is None. :type top: int - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobExecutionListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobExecutionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobExecution or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobExecution] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecutionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecutionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_job_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, job_name=job_name, subscription_id=self._config.subscription_id, - api_version=api_version, create_time_min=create_time_min, create_time_max=create_time_max, end_time_min=end_time_min, @@ -776,7 +696,8 @@ def prepare_request(next_link=None): is_active=is_active, skip=skip, top=top, - template_url=self.list_by_job.metadata['url'], + api_version=api_version, + template_url=self.list_by_job.metadata["url"], headers=_headers, params=_params, ) @@ -784,25 +705,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_job_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - job_name=job_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - create_time_min=create_time_min, - create_time_max=create_time_max, - end_time_min=end_time_min, - end_time_max=end_time_max, - is_active=is_active, - skip=skip, - top=top, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -818,10 +721,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -831,11 +732,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_job.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions"} # type: ignore + list_by_job.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions"} # type: ignore @distributed_trace def get( @@ -850,36 +749,30 @@ def get( """Gets a job execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job. + :param job_name: The name of the job. Required. :type job_name: str - :param job_execution_id: The id of the job execution. + :param job_execution_id: The id of the job execution. Required. :type job_execution_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobExecution, or the result of cls(response) + :return: JobExecution or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobExecution - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecution] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecution] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -888,7 +781,7 @@ def get( job_execution_id=job_execution_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -896,25 +789,23 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobExecution', pipeline_response) + deserialized = self._deserialize("JobExecution", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}"} # type: ignore def _create_or_update_initial( self, @@ -925,19 +816,16 @@ def _create_or_update_initial( job_execution_id: str, **kwargs: Any ) -> Optional[_models.JobExecution]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.JobExecution]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.JobExecution]] - - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, @@ -945,7 +833,7 @@ def _create_or_update_initial( job_execution_id=job_execution_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._create_or_update_initial.metadata['url'], + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -953,10 +841,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -965,18 +852,17 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('JobExecution', pipeline_response) + deserialized = self._deserialize("JobExecution", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('JobExecution', pipeline_response) + deserialized = self._deserialize("JobExecution", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}"} # type: ignore @distributed_trace def begin_create_or_update( @@ -991,19 +877,16 @@ def begin_create_or_update( """Creates or updates a job execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :param job_execution_id: The job execution id to create the job execution under. + :param job_execution_id: The job execution id to create the job execution under. Required. :type job_execution_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1015,19 +898,16 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either JobExecution or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.JobExecution] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecution] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecution] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -1036,36 +916,32 @@ def begin_create_or_update( job_name=job_name, job_execution_id=job_execution_id, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('JobExecution', pipeline_response) + deserialized = self._deserialize("JobExecution", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_step_executions_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_step_executions_operations.py index 11aea472cd391..793d5219d24e4 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_step_executions_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_step_executions_operations.py @@ -9,9 +9,13 @@ import datetime from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -21,13 +25,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_job_execution_request( resource_group_name: str, server_name: str, @@ -48,49 +55,46 @@ def build_list_by_job_execution_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "jobExecutionId": _SERIALIZER.url("job_execution_id", job_execution_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "jobExecutionId": _SERIALIZER.url("job_execution_id", job_execution_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if create_time_min is not None: - _params['createTimeMin'] = _SERIALIZER.query("create_time_min", create_time_min, 'iso-8601') + _params["createTimeMin"] = _SERIALIZER.query("create_time_min", create_time_min, "iso-8601") if create_time_max is not None: - _params['createTimeMax'] = _SERIALIZER.query("create_time_max", create_time_max, 'iso-8601') + _params["createTimeMax"] = _SERIALIZER.query("create_time_max", create_time_max, "iso-8601") if end_time_min is not None: - _params['endTimeMin'] = _SERIALIZER.query("end_time_min", end_time_min, 'iso-8601') + _params["endTimeMin"] = _SERIALIZER.query("end_time_min", end_time_min, "iso-8601") if end_time_max is not None: - _params['endTimeMax'] = _SERIALIZER.query("end_time_max", end_time_max, 'iso-8601') + _params["endTimeMax"] = _SERIALIZER.query("end_time_max", end_time_max, "iso-8601") if is_active is not None: - _params['isActive'] = _SERIALIZER.query("is_active", is_active, 'bool') + _params["isActive"] = _SERIALIZER.query("is_active", is_active, "bool") if skip is not None: - _params['$skip'] = _SERIALIZER.query("skip", skip, 'int') + _params["$skip"] = _SERIALIZER.query("skip", skip, "int") if top is not None: - _params['$top'] = _SERIALIZER.query("top", top, 'int') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$top"] = _SERIALIZER.query("top", top, "int") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -106,36 +110,34 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "jobExecutionId": _SERIALIZER.url("job_execution_id", job_execution_id, 'str'), - "stepName": _SERIALIZER.url("step_name", step_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "jobExecutionId": _SERIALIZER.url("job_execution_id", job_execution_id, "str"), + "stepName": _SERIALIZER.url("step_name", step_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class JobStepExecutionsOperations: """ @@ -156,7 +158,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_job_execution( self, @@ -173,19 +174,19 @@ def list_by_job_execution( skip: Optional[int] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable[_models.JobExecutionListResult]: + ) -> Iterable["_models.JobExecution"]: """Lists the step executions of a job execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :param job_execution_id: The id of the job execution. + :param job_execution_id: The id of the job execution. Required. :type job_execution_id: str :param create_time_min: If specified, only job executions created at or after the specified time are included. Default value is None. @@ -206,28 +207,23 @@ def list_by_job_execution( :type skip: int :param top: The number of elements to return from the collection. Default value is None. :type top: int - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobExecutionListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobExecutionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobExecution or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobExecution] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecutionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecutionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_job_execution_request( resource_group_name=resource_group_name, server_name=server_name, @@ -235,7 +231,6 @@ def prepare_request(next_link=None): job_name=job_name, job_execution_id=job_execution_id, subscription_id=self._config.subscription_id, - api_version=api_version, create_time_min=create_time_min, create_time_max=create_time_max, end_time_min=end_time_min, @@ -243,7 +238,8 @@ def prepare_request(next_link=None): is_active=is_active, skip=skip, top=top, - template_url=self.list_by_job_execution.metadata['url'], + api_version=api_version, + template_url=self.list_by_job_execution.metadata["url"], headers=_headers, params=_params, ) @@ -251,26 +247,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_job_execution_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - job_name=job_name, - job_execution_id=job_execution_id, - subscription_id=self._config.subscription_id, - api_version=api_version, - create_time_min=create_time_min, - create_time_max=create_time_max, - end_time_min=end_time_min, - end_time_max=end_time_max, - is_active=is_active, - skip=skip, - top=top, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -286,10 +263,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -299,11 +274,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_job_execution.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps"} # type: ignore + list_by_job_execution.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps"} # type: ignore @distributed_trace def get( @@ -319,38 +292,32 @@ def get( """Gets a step execution of a job execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :param job_execution_id: The unique id of the job execution. + :param job_execution_id: The unique id of the job execution. Required. :type job_execution_id: str - :param step_name: The name of the step. + :param step_name: The name of the step. Required. :type step_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobExecution, or the result of cls(response) + :return: JobExecution or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobExecution - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecution] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecution] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -360,7 +327,7 @@ def get( step_name=step_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -368,22 +335,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobExecution', pipeline_response) + deserialized = self._deserialize("JobExecution", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_steps_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_steps_operations.py index 3f30c335ea403..04b7dfce518d3 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_steps_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_steps_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_version_request( resource_group_name: str, server_name: str, @@ -39,35 +46,32 @@ def build_list_by_version_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}/steps") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}/steps", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "jobVersion": _SERIALIZER.url("job_version", job_version, 'int'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "jobVersion": _SERIALIZER.url("job_version", job_version, "int"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_by_version_request( @@ -83,77 +87,66 @@ def build_get_by_version_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}/steps/{stepName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}/steps/{stepName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "jobVersion": _SERIALIZER.url("job_version", job_version, 'int'), - "stepName": _SERIALIZER.url("step_name", step_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "jobVersion": _SERIALIZER.url("job_version", job_version, "int"), + "stepName": _SERIALIZER.url("step_name", step_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_job_request( - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -168,35 +161,32 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "stepName": _SERIALIZER.url("step_name", step_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "stepName": _SERIALIZER.url("step_name", step_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( @@ -206,48 +196,40 @@ def build_create_or_update_request( job_name: str, step_name: str, subscription_id: str, - *, - json: Optional[_models.JobStep] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "stepName": _SERIALIZER.url("step_name", step_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "stepName": _SERIALIZER.url("step_name", step_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_delete_request( @@ -261,29 +243,28 @@ def build_delete_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "stepName": _SERIALIZER.url("step_name", step_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "stepName": _SERIALIZER.url("step_name", step_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) class JobStepsOperations: """ @@ -304,7 +285,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_version( self, @@ -314,41 +294,37 @@ def list_by_version( job_name: str, job_version: int, **kwargs: Any - ) -> Iterable[_models.JobStepListResult]: + ) -> Iterable["_models.JobStep"]: """Gets all job steps in the specified job version. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :param job_version: The version of the job to get. + :param job_version: The version of the job to get. Required. :type job_version: int - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobStepListResult or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobStepListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobStep or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobStep] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobStepListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobStepListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_version_request( resource_group_name=resource_group_name, server_name=server_name, @@ -357,7 +333,7 @@ def prepare_request(next_link=None): job_version=job_version, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_version.metadata['url'], + template_url=self.list_by_version.metadata["url"], headers=_headers, params=_params, ) @@ -365,19 +341,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_version_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - job_name=job_name, - job_version=job_version, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -393,10 +357,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -406,11 +368,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_version.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}/steps"} # type: ignore + list_by_version.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}/steps"} # type: ignore @distributed_trace def get_by_version( @@ -426,38 +386,32 @@ def get_by_version( """Gets the specified version of a job step. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job. + :param job_name: The name of the job. Required. :type job_name: str - :param job_version: The version of the job to get. + :param job_version: The version of the job to get. Required. :type job_version: int - :param step_name: The name of the job step. + :param step_name: The name of the job step. Required. :type step_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobStep, or the result of cls(response) + :return: JobStep or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobStep - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobStep] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobStep] - request = build_get_by_version_request( resource_group_name=resource_group_name, server_name=server_name, @@ -467,7 +421,7 @@ def get_by_version( step_name=step_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get_by_version.metadata['url'], + template_url=self.get_by_version.metadata["url"], headers=_headers, params=_params, ) @@ -475,67 +429,56 @@ def get_by_version( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobStep', pipeline_response) + deserialized = self._deserialize("JobStep", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get_by_version.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}/steps/{stepName}"} # type: ignore - + get_by_version.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}/steps/{stepName}"} # type: ignore @distributed_trace def list_by_job( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - **kwargs: Any - ) -> Iterable[_models.JobStepListResult]: + self, resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, **kwargs: Any + ) -> Iterable["_models.JobStep"]: """Gets all job steps for a job's current version. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobStepListResult or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobStepListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobStep or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobStep] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobStepListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobStepListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_job_request( resource_group_name=resource_group_name, server_name=server_name, @@ -543,7 +486,7 @@ def prepare_request(next_link=None): job_name=job_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_job.metadata['url'], + template_url=self.list_by_job.metadata["url"], headers=_headers, params=_params, ) @@ -551,18 +494,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_job_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - job_name=job_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -578,10 +510,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -591,11 +521,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_job.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps"} # type: ignore + list_by_job.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps"} # type: ignore @distributed_trace def get( @@ -610,36 +538,30 @@ def get( """Gets a job step in a job's current version. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job. + :param job_name: The name of the job. Required. :type job_name: str - :param step_name: The name of the job step. + :param step_name: The name of the job step. Required. :type step_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobStep, or the result of cls(response) + :return: JobStep or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobStep - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobStep] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobStep] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -648,7 +570,7 @@ def get( step_name=step_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -656,27 +578,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobStep', pipeline_response) + deserialized = self._deserialize("JobStep", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, @@ -685,44 +605,123 @@ def create_or_update( job_name: str, step_name: str, parameters: _models.JobStep, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.JobStep: """Creates or updates a job step. This will implicitly create a new job version. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job. + :param job_name: The name of the job. Required. :type job_name: str - :param step_name: The name of the job step. + :param step_name: The name of the job step. Required. :type step_name: str - :param parameters: The requested state of the job step. + :param parameters: The requested state of the job step. Required. :type parameters: ~azure.mgmt.sql.models.JobStep - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: JobStep or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.JobStep + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + job_name: str, + step_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.JobStep: + """Creates or updates a job step. This will implicitly create a new job version. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent. Required. + :type job_agent_name: str + :param job_name: The name of the job. Required. + :type job_name: str + :param step_name: The name of the job step. Required. + :type step_name: str + :param parameters: The requested state of the job step. Required. + :type parameters: IO + :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: JobStep or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.JobStep + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + job_name: str, + step_name: str, + parameters: Union[_models.JobStep, IO], + **kwargs: Any + ) -> _models.JobStep: + """Creates or updates a job step. This will implicitly create a new job version. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent. Required. + :type job_agent_name: str + :param job_name: The name of the job. Required. + :type job_name: str + :param step_name: The name of the job step. Required. + :type step_name: str + :param parameters: The requested state of the job step. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.JobStep 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 - :return: JobStep, or the result of cls(response) + :return: JobStep or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobStep - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobStep] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobStep] - _json = self._serialize.body(parameters, 'JobStep') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "JobStep") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -734,7 +733,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -742,10 +742,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -753,18 +752,17 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('JobStep', pipeline_response) + deserialized = self._deserialize("JobStep", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('JobStep', pipeline_response) + deserialized = self._deserialize("JobStep", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}"} # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -779,36 +777,30 @@ def delete( # pylint: disable=inconsistent-return-statements """Deletes a job step. This will implicitly create a new job version. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job. + :param job_name: The name of the job. Required. :type job_name: str - :param step_name: The name of the job step to delete. + :param step_name: The name of the job step to delete. Required. :type step_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -817,7 +809,7 @@ def delete( # pylint: disable=inconsistent-return-statements step_name=step_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -825,10 +817,9 @@ def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 204]: @@ -838,5 +829,4 @@ def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_target_executions_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_target_executions_operations.py index 39feafb2895bd..2ac9063e1321c 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_target_executions_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_target_executions_operations.py @@ -9,9 +9,13 @@ import datetime from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -21,13 +25,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_job_execution_request( resource_group_name: str, server_name: str, @@ -48,49 +55,46 @@ def build_list_by_job_execution_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/targets") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/targets", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "jobExecutionId": _SERIALIZER.url("job_execution_id", job_execution_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "jobExecutionId": _SERIALIZER.url("job_execution_id", job_execution_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if create_time_min is not None: - _params['createTimeMin'] = _SERIALIZER.query("create_time_min", create_time_min, 'iso-8601') + _params["createTimeMin"] = _SERIALIZER.query("create_time_min", create_time_min, "iso-8601") if create_time_max is not None: - _params['createTimeMax'] = _SERIALIZER.query("create_time_max", create_time_max, 'iso-8601') + _params["createTimeMax"] = _SERIALIZER.query("create_time_max", create_time_max, "iso-8601") if end_time_min is not None: - _params['endTimeMin'] = _SERIALIZER.query("end_time_min", end_time_min, 'iso-8601') + _params["endTimeMin"] = _SERIALIZER.query("end_time_min", end_time_min, "iso-8601") if end_time_max is not None: - _params['endTimeMax'] = _SERIALIZER.query("end_time_max", end_time_max, 'iso-8601') + _params["endTimeMax"] = _SERIALIZER.query("end_time_max", end_time_max, "iso-8601") if is_active is not None: - _params['isActive'] = _SERIALIZER.query("is_active", is_active, 'bool') + _params["isActive"] = _SERIALIZER.query("is_active", is_active, "bool") if skip is not None: - _params['$skip'] = _SERIALIZER.query("skip", skip, 'int') + _params["$skip"] = _SERIALIZER.query("skip", skip, "int") if top is not None: - _params['$top'] = _SERIALIZER.query("top", top, 'int') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$top"] = _SERIALIZER.query("top", top, "int") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_step_request( @@ -114,50 +118,47 @@ def build_list_by_step_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}/targets") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}/targets", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "jobExecutionId": _SERIALIZER.url("job_execution_id", job_execution_id, 'str'), - "stepName": _SERIALIZER.url("step_name", step_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "jobExecutionId": _SERIALIZER.url("job_execution_id", job_execution_id, "str"), + "stepName": _SERIALIZER.url("step_name", step_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if create_time_min is not None: - _params['createTimeMin'] = _SERIALIZER.query("create_time_min", create_time_min, 'iso-8601') + _params["createTimeMin"] = _SERIALIZER.query("create_time_min", create_time_min, "iso-8601") if create_time_max is not None: - _params['createTimeMax'] = _SERIALIZER.query("create_time_max", create_time_max, 'iso-8601') + _params["createTimeMax"] = _SERIALIZER.query("create_time_max", create_time_max, "iso-8601") if end_time_min is not None: - _params['endTimeMin'] = _SERIALIZER.query("end_time_min", end_time_min, 'iso-8601') + _params["endTimeMin"] = _SERIALIZER.query("end_time_min", end_time_min, "iso-8601") if end_time_max is not None: - _params['endTimeMax'] = _SERIALIZER.query("end_time_max", end_time_max, 'iso-8601') + _params["endTimeMax"] = _SERIALIZER.query("end_time_max", end_time_max, "iso-8601") if is_active is not None: - _params['isActive'] = _SERIALIZER.query("is_active", is_active, 'bool') + _params["isActive"] = _SERIALIZER.query("is_active", is_active, "bool") if skip is not None: - _params['$skip'] = _SERIALIZER.query("skip", skip, 'int') + _params["$skip"] = _SERIALIZER.query("skip", skip, "int") if top is not None: - _params['$top'] = _SERIALIZER.query("top", top, 'int') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$top"] = _SERIALIZER.query("top", top, "int") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -174,37 +175,35 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}/targets/{targetId}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}/targets/{targetId}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "jobExecutionId": _SERIALIZER.url("job_execution_id", job_execution_id, 'str'), - "stepName": _SERIALIZER.url("step_name", step_name, 'str'), - "targetId": _SERIALIZER.url("target_id", target_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "jobExecutionId": _SERIALIZER.url("job_execution_id", job_execution_id, "str"), + "stepName": _SERIALIZER.url("step_name", step_name, "str"), + "targetId": _SERIALIZER.url("target_id", target_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class JobTargetExecutionsOperations: """ @@ -225,7 +224,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_job_execution( self, @@ -242,19 +240,19 @@ def list_by_job_execution( skip: Optional[int] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable[_models.JobExecutionListResult]: + ) -> Iterable["_models.JobExecution"]: """Lists target executions for all steps of a job execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :param job_execution_id: The id of the job execution. + :param job_execution_id: The id of the job execution. Required. :type job_execution_id: str :param create_time_min: If specified, only job executions created at or after the specified time are included. Default value is None. @@ -275,28 +273,23 @@ def list_by_job_execution( :type skip: int :param top: The number of elements to return from the collection. Default value is None. :type top: int - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobExecutionListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobExecutionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobExecution or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobExecution] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecutionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecutionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_job_execution_request( resource_group_name=resource_group_name, server_name=server_name, @@ -304,7 +297,6 @@ def prepare_request(next_link=None): job_name=job_name, job_execution_id=job_execution_id, subscription_id=self._config.subscription_id, - api_version=api_version, create_time_min=create_time_min, create_time_max=create_time_max, end_time_min=end_time_min, @@ -312,7 +304,8 @@ def prepare_request(next_link=None): is_active=is_active, skip=skip, top=top, - template_url=self.list_by_job_execution.metadata['url'], + api_version=api_version, + template_url=self.list_by_job_execution.metadata["url"], headers=_headers, params=_params, ) @@ -320,26 +313,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_job_execution_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - job_name=job_name, - job_execution_id=job_execution_id, - subscription_id=self._config.subscription_id, - api_version=api_version, - create_time_min=create_time_min, - create_time_max=create_time_max, - end_time_min=end_time_min, - end_time_max=end_time_max, - is_active=is_active, - skip=skip, - top=top, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -355,10 +329,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -368,11 +340,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_job_execution.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/targets"} # type: ignore + list_by_job_execution.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/targets"} # type: ignore @distributed_trace def list_by_step( @@ -391,21 +361,21 @@ def list_by_step( skip: Optional[int] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable[_models.JobExecutionListResult]: + ) -> Iterable["_models.JobExecution"]: """Lists the target executions of a job step execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :param job_execution_id: The id of the job execution. + :param job_execution_id: The id of the job execution. Required. :type job_execution_id: str - :param step_name: The name of the step. + :param step_name: The name of the step. Required. :type step_name: str :param create_time_min: If specified, only job executions created at or after the specified time are included. Default value is None. @@ -426,28 +396,23 @@ def list_by_step( :type skip: int :param top: The number of elements to return from the collection. Default value is None. :type top: int - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobExecutionListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobExecutionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobExecution or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobExecution] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecutionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecutionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_step_request( resource_group_name=resource_group_name, server_name=server_name, @@ -456,7 +421,6 @@ def prepare_request(next_link=None): job_execution_id=job_execution_id, step_name=step_name, subscription_id=self._config.subscription_id, - api_version=api_version, create_time_min=create_time_min, create_time_max=create_time_max, end_time_min=end_time_min, @@ -464,7 +428,8 @@ def prepare_request(next_link=None): is_active=is_active, skip=skip, top=top, - template_url=self.list_by_step.metadata['url'], + api_version=api_version, + template_url=self.list_by_step.metadata["url"], headers=_headers, params=_params, ) @@ -472,27 +437,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_step_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - job_name=job_name, - job_execution_id=job_execution_id, - step_name=step_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - create_time_min=create_time_min, - create_time_max=create_time_max, - end_time_min=end_time_min, - end_time_max=end_time_max, - is_active=is_active, - skip=skip, - top=top, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -508,10 +453,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -521,11 +464,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_step.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}/targets"} # type: ignore + list_by_step.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}/targets"} # type: ignore @distributed_trace def get( @@ -542,40 +483,34 @@ def get( """Gets a target execution. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :param job_execution_id: The unique id of the job execution. + :param job_execution_id: The unique id of the job execution. Required. :type job_execution_id: str - :param step_name: The name of the step. + :param step_name: The name of the step. Required. :type step_name: str - :param target_id: The target id. + :param target_id: The target id. Required. :type target_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobExecution, or the result of cls(response) + :return: JobExecution or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobExecution - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobExecution] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobExecution] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -586,7 +521,7 @@ def get( target_id=target_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -594,22 +529,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobExecution', pipeline_response) + deserialized = self._deserialize("JobExecution", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}/targets/{targetId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}/targets/{targetId}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_target_groups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_target_groups_operations.py index 106e559e1a3ec..2e4ab7d238f91 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_target_groups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_target_groups_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,50 +24,46 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_agent_request( - resource_group_name: str, - server_name: str, - job_agent_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, job_agent_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -77,34 +77,31 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "targetGroupName": _SERIALIZER.url("target_group_name", target_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "targetGroupName": _SERIALIZER.url("target_group_name", target_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( @@ -113,47 +110,39 @@ def build_create_or_update_request( job_agent_name: str, target_group_name: str, subscription_id: str, - *, - json: Optional[_models.JobTargetGroup] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "targetGroupName": _SERIALIZER.url("target_group_name", target_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "targetGroupName": _SERIALIZER.url("target_group_name", target_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_delete_request( @@ -166,28 +155,27 @@ def build_delete_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "targetGroupName": _SERIALIZER.url("target_group_name", target_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "targetGroupName": _SERIALIZER.url("target_group_name", target_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) class JobTargetGroupsOperations: """ @@ -208,53 +196,43 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_agent( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - **kwargs: Any - ) -> Iterable[_models.JobTargetGroupListResult]: + self, resource_group_name: str, server_name: str, job_agent_name: str, **kwargs: Any + ) -> Iterable["_models.JobTargetGroup"]: """Gets all target groups in an agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobTargetGroupListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobTargetGroupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobTargetGroup or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobTargetGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobTargetGroupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobTargetGroupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_agent_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_agent.metadata['url'], + template_url=self.list_by_agent.metadata["url"], headers=_headers, params=_params, ) @@ -262,17 +240,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_agent_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -288,10 +256,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -301,52 +267,39 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_agent.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups"} # type: ignore + list_by_agent.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - target_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, target_group_name: str, **kwargs: Any ) -> _models.JobTargetGroup: """Gets a target group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param target_group_name: The name of the target group. + :param target_group_name: The name of the target group. Required. :type target_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobTargetGroup, or the result of cls(response) + :return: JobTargetGroup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobTargetGroup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobTargetGroup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobTargetGroup] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -354,7 +307,7 @@ def get( target_group_name=target_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -362,27 +315,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobTargetGroup', pipeline_response) + deserialized = self._deserialize("JobTargetGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, @@ -390,42 +341,115 @@ def create_or_update( job_agent_name: str, target_group_name: str, parameters: _models.JobTargetGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.JobTargetGroup: """Creates or updates a target group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param target_group_name: The name of the target group. + :param target_group_name: The name of the target group. Required. :type target_group_name: str - :param parameters: The requested state of the target group. + :param parameters: The requested state of the target group. Required. :type parameters: ~azure.mgmt.sql.models.JobTargetGroup - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: JobTargetGroup or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.JobTargetGroup + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + target_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.JobTargetGroup: + """Creates or updates a target group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent. Required. + :type job_agent_name: str + :param target_group_name: The name of the target group. Required. + :type target_group_name: str + :param parameters: The requested state of the target group. Required. + :type parameters: IO + :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: JobTargetGroup, or the result of cls(response) + :return: JobTargetGroup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobTargetGroup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + target_group_name: str, + parameters: Union[_models.JobTargetGroup, IO], + **kwargs: Any + ) -> _models.JobTargetGroup: + """Creates or updates a target group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent. Required. + :type job_agent_name: str + :param target_group_name: The name of the target group. Required. + :type target_group_name: str + :param parameters: The requested state of the target group. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.JobTargetGroup 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 + :return: JobTargetGroup or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.JobTargetGroup + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobTargetGroup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobTargetGroup] - _json = self._serialize.body(parameters, 'JobTargetGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "JobTargetGroup") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -436,7 +460,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -444,10 +469,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -455,59 +479,47 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('JobTargetGroup', pipeline_response) + deserialized = self._deserialize("JobTargetGroup", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('JobTargetGroup', pipeline_response) + deserialized = self._deserialize("JobTargetGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}"} # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - target_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, target_group_name: str, **kwargs: Any ) -> None: """Deletes a target group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param target_group_name: The name of the target group. + :param target_group_name: The name of the target group. Required. :type target_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -515,7 +527,7 @@ def delete( # pylint: disable=inconsistent-return-statements target_group_name=target_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -523,10 +535,9 @@ def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 204]: @@ -536,5 +547,4 @@ def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/targetGroups/{targetGroupName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_versions_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_versions_operations.py index bbb0f4232ef8a..042adf51146a1 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_versions_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_job_versions_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,52 +24,47 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_job_request( - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -80,35 +79,33 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "jobVersion": _SERIALIZER.url("job_version", job_version, 'int'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "jobVersion": _SERIALIZER.url("job_version", job_version, "int"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class JobVersionsOperations: """ @@ -129,49 +126,38 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_job( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - **kwargs: Any - ) -> Iterable[_models.JobVersionListResult]: + self, resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, **kwargs: Any + ) -> Iterable["_models.JobVersion"]: """Gets all versions of a job. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobVersionListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobVersionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either JobVersion or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobVersion] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobVersionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobVersionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_job_request( resource_group_name=resource_group_name, server_name=server_name, @@ -179,7 +165,7 @@ def prepare_request(next_link=None): job_name=job_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_job.metadata['url'], + template_url=self.list_by_job.metadata["url"], headers=_headers, params=_params, ) @@ -187,18 +173,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_job_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - job_name=job_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -214,10 +189,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -227,11 +200,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_job.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions"} # type: ignore + list_by_job.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions"} # type: ignore @distributed_trace def get( @@ -246,36 +217,30 @@ def get( """Gets a job version. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job. + :param job_name: The name of the job. Required. :type job_name: str - :param job_version: The version of the job to get. + :param job_version: The version of the job to get. Required. :type job_version: int - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: JobVersion, or the result of cls(response) + :return: JobVersion or the result of cls(response) :rtype: ~azure.mgmt.sql.models.JobVersion - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobVersion] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobVersion] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -284,7 +249,7 @@ def get( job_version=job_version, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -292,22 +257,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('JobVersion', pipeline_response) + deserialized = self._deserialize("JobVersion", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_jobs_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_jobs_operations.py index 1a8e40c915b58..e46f78a080644 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_jobs_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_jobs_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,174 +24,143 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_agent_request( - resource_group_name: str, - server_name: str, - job_agent_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, job_agent_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - subscription_id: str, - *, - json: Optional[_models.Job] = None, - content: Any = None, - **kwargs: Any + resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_delete_request( - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, 'str'), - "jobName": _SERIALIZER.url("job_name", job_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "jobAgentName": _SERIALIZER.url("job_agent_name", job_agent_name, "str"), + "jobName": _SERIALIZER.url("job_name", job_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) class JobsOperations: """ @@ -208,52 +181,43 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_agent( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - **kwargs: Any - ) -> Iterable[_models.JobListResult]: + self, resource_group_name: str, server_name: str, job_agent_name: str, **kwargs: Any + ) -> Iterable["_models.Job"]: """Gets a list of jobs. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either JobListResult or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.JobListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Job or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.Job] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.JobListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.JobListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_agent_request( resource_group_name=resource_group_name, server_name=server_name, job_agent_name=job_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_agent.metadata['url'], + template_url=self.list_by_agent.metadata["url"], headers=_headers, params=_params, ) @@ -261,17 +225,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_agent_request( - resource_group_name=resource_group_name, - server_name=server_name, - job_agent_name=job_agent_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -287,10 +241,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -300,52 +252,39 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_agent.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs"} # type: ignore + list_by_agent.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, **kwargs: Any ) -> _models.Job: """Gets a job. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Job, or the result of cls(response) + :return: Job or the result of cls(response) :rtype: ~azure.mgmt.sql.models.Job - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.Job] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.Job] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -353,7 +292,7 @@ def get( job_name=job_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -361,27 +300,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('Job', pipeline_response) + deserialized = self._deserialize("Job", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, @@ -389,42 +326,114 @@ def create_or_update( job_agent_name: str, job_name: str, parameters: _models.Job, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.Job: """Creates or updates a job. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to get. + :param job_name: The name of the job to get. Required. :type job_name: str - :param parameters: The requested job state. + :param parameters: The requested job state. Required. :type parameters: ~azure.mgmt.sql.models.Job - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: Job, or the result of cls(response) + :return: Job or the result of cls(response) :rtype: ~azure.mgmt.sql.models.Job - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + job_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.Job: + """Creates or updates a job. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent. Required. + :type job_agent_name: str + :param job_name: The name of the job to get. Required. + :type job_name: str + :param parameters: The requested job state. Required. + :type parameters: IO + :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: Job or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.Job + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + job_agent_name: str, + job_name: str, + parameters: Union[_models.Job, IO], + **kwargs: Any + ) -> _models.Job: + """Creates or updates a job. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param job_agent_name: The name of the job agent. Required. + :type job_agent_name: str + :param job_name: The name of the job to get. Required. + :type job_name: str + :param parameters: The requested job state. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.Job 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 + :return: Job or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.Job + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.Job] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.Job] - _json = self._serialize.body(parameters, 'Job') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "Job") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -435,7 +444,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -443,10 +453,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -454,59 +463,47 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('Job', pipeline_response) + deserialized = self._deserialize("Job", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('Job', pipeline_response) + deserialized = self._deserialize("Job", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}"} # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - job_agent_name: str, - job_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, job_agent_name: str, job_name: str, **kwargs: Any ) -> None: """Deletes a job. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param job_agent_name: The name of the job agent. + :param job_agent_name: The name of the job agent. Required. :type job_agent_name: str - :param job_name: The name of the job to delete. + :param job_name: The name of the job to delete. Required. :type job_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -514,7 +511,7 @@ def delete( # pylint: disable=inconsistent-return-statements job_name=job_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -522,10 +519,9 @@ def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 204]: @@ -535,5 +531,4 @@ def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_ledger_digest_uploads_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_ledger_digest_uploads_operations.py index e78f812134c95..c4cc4c8ca4190 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_ledger_digest_uploads_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_ledger_digest_uploads_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -40,125 +47,107 @@ 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', "2021-02-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "ledgerDigestUploads": _SERIALIZER.url("ledger_digest_uploads", ledger_digest_uploads, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "ledgerDigestUploads": _SERIALIZER.url("ledger_digest_uploads", ledger_digest_uploads, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, server_name: str, database_name: str, ledger_digest_uploads: Union[str, "_models.LedgerDigestUploadsName"], subscription_id: str, - *, - json: Optional[_models.LedgerDigestUploads] = None, - content: Any = None, **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', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "ledgerDigestUploads": _SERIALIZER.url("ledger_digest_uploads", ledger_digest_uploads, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "ledgerDigestUploads": _SERIALIZER.url("ledger_digest_uploads", ledger_digest_uploads, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_database_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-02-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_disable_request_initial( +def build_disable_request( resource_group_name: str, server_name: str, database_name: str, @@ -169,34 +158,32 @@ def build_disable_request_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', "2021-02-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}/disable") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}/disable", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "ledgerDigestUploads": _SERIALIZER.url("ledger_digest_uploads", ledger_digest_uploads, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "ledgerDigestUploads": _SERIALIZER.url("ledger_digest_uploads", ledger_digest_uploads, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class LedgerDigestUploadsOperations: """ @@ -217,7 +204,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -230,34 +216,28 @@ def get( """Gets the current ledger digest upload configuration for a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param ledger_digest_uploads: + :param ledger_digest_uploads: "current" Required. :type ledger_digest_uploads: str or ~azure.mgmt.sql.models.LedgerDigestUploadsName - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: LedgerDigestUploads, or the result of cls(response) + :return: LedgerDigestUploads or the result of cls(response) :rtype: ~azure.mgmt.sql.models.LedgerDigestUploads - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LedgerDigestUploads] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LedgerDigestUploads] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -265,7 +245,7 @@ def get( ledger_digest_uploads=ledger_digest_uploads, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -273,25 +253,23 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('LedgerDigestUploads', pipeline_response) + deserialized = self._deserialize("LedgerDigestUploads", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}"} # type: ignore def _create_or_update_initial( self, @@ -299,24 +277,28 @@ def _create_or_update_initial( server_name: str, database_name: str, ledger_digest_uploads: Union[str, "_models.LedgerDigestUploadsName"], - parameters: _models.LedgerDigestUploads, + parameters: Union[_models.LedgerDigestUploads, IO], **kwargs: Any ) -> Optional[_models.LedgerDigestUploads]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.LedgerDigestUploads]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.LedgerDigestUploads]] - _json = self._serialize.body(parameters, 'LedgerDigestUploads') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "LedgerDigestUploads") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -325,7 +307,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -333,10 +316,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -345,17 +327,16 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('LedgerDigestUploads', pipeline_response) + deserialized = self._deserialize("LedgerDigestUploads", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, @@ -363,25 +344,70 @@ def begin_create_or_update( database_name: str, ledger_digest_uploads: Union[str, "_models.LedgerDigestUploadsName"], parameters: _models.LedgerDigestUploads, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.LedgerDigestUploads]: """Enables upload ledger digests to an Azure Storage account or an Azure Confidential Ledger instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param ledger_digest_uploads: + :param ledger_digest_uploads: "current" Required. :type ledger_digest_uploads: str or ~azure.mgmt.sql.models.LedgerDigestUploadsName - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.LedgerDigestUploads - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 LedgerDigestUploads or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LedgerDigestUploads] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + ledger_digest_uploads: Union[str, "_models.LedgerDigestUploadsName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.LedgerDigestUploads]: + """Enables upload ledger digests to an Azure Storage account or an Azure Confidential Ledger + instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param ledger_digest_uploads: "current" Required. + :type ledger_digest_uploads: str or ~azure.mgmt.sql.models.LedgerDigestUploadsName + :param parameters: Required. + :type parameters: IO + :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 @@ -393,20 +419,58 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either LedgerDigestUploads or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LedgerDigestUploads] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + ledger_digest_uploads: Union[str, "_models.LedgerDigestUploadsName"], + parameters: Union[_models.LedgerDigestUploads, IO], + **kwargs: Any + ) -> LROPoller[_models.LedgerDigestUploads]: + """Enables upload ledger digests to an Azure Storage account or an Azure Confidential Ledger + instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param ledger_digest_uploads: "current" Required. + :type ledger_digest_uploads: str or ~azure.mgmt.sql.models.LedgerDigestUploadsName + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.LedgerDigestUploads 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. + :return: An instance of LROPoller that returns either LedgerDigestUploads or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LedgerDigestUploads] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.LedgerDigestUploads] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.LedgerDigestUploads] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -416,86 +480,73 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('LedgerDigestUploads', pipeline_response) + deserialized = self._deserialize("LedgerDigestUploads", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.LedgerDigestUploadsListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.LedgerDigestUploads"]: """Gets all ledger digest upload settings on a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LedgerDigestUploadsListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LedgerDigestUploadsListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either LedgerDigestUploads or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LedgerDigestUploads] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LedgerDigestUploadsListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LedgerDigestUploadsListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -503,17 +554,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -529,10 +570,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -542,11 +581,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads"} # type: ignore def _disable_initial( self, @@ -556,26 +593,23 @@ def _disable_initial( ledger_digest_uploads: Union[str, "_models.LedgerDigestUploadsName"], **kwargs: Any ) -> Optional[_models.LedgerDigestUploads]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.LedgerDigestUploads]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.LedgerDigestUploads]] - - request = build_disable_request_initial( + request = build_disable_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, ledger_digest_uploads=ledger_digest_uploads, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._disable_initial.metadata['url'], + template_url=self._disable_initial.metadata["url"], headers=_headers, params=_params, ) @@ -583,10 +617,9 @@ def _disable_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -595,15 +628,14 @@ def _disable_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('LedgerDigestUploads', pipeline_response) + deserialized = self._deserialize("LedgerDigestUploads", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _disable_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}/disable"} # type: ignore - + _disable_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}/disable"} # type: ignore @distributed_trace def begin_disable( @@ -618,17 +650,14 @@ def begin_disable( instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param ledger_digest_uploads: + :param ledger_digest_uploads: "current" Required. :type ledger_digest_uploads: str or ~azure.mgmt.sql.models.LedgerDigestUploadsName - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -640,19 +669,16 @@ def begin_disable( :return: An instance of LROPoller that returns either LedgerDigestUploads or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LedgerDigestUploads] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LedgerDigestUploads] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LedgerDigestUploads] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._disable_initial( # type: ignore resource_group_name=resource_group_name, @@ -660,36 +686,32 @@ def begin_disable( database_name=database_name, ledger_digest_uploads=ledger_digest_uploads, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('LedgerDigestUploads', pipeline_response) + deserialized = self._deserialize("LedgerDigestUploads", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_disable.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}/disable"} # type: ignore + begin_disable.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}/disable"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_long_term_retention_backups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_long_term_retention_backups_operations.py index 25b4aeb190fc0..d129fe064633d 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_long_term_retention_backups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_long_term_retention_backups_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,109 +26,104 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False -def build_copy_request_initial( + +def build_copy_request( location_name: str, long_term_retention_server_name: str, long_term_retention_database_name: str, backup_name: str, subscription_id: str, - *, - json: Optional[_models.CopyLongTermRetentionBackupParameters] = None, - content: Any = None, **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', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "longTermRetentionServerName": _SERIALIZER.url("long_term_retention_server_name", long_term_retention_server_name, 'str'), - "longTermRetentionDatabaseName": _SERIALIZER.url("long_term_retention_database_name", long_term_retention_database_name, 'str'), - "backupName": _SERIALIZER.url("backup_name", backup_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "longTermRetentionServerName": _SERIALIZER.url( + "long_term_retention_server_name", long_term_retention_server_name, "str" + ), + "longTermRetentionDatabaseName": _SERIALIZER.url( + "long_term_retention_database_name", long_term_retention_database_name, "str" + ), + "backupName": _SERIALIZER.url("backup_name", backup_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) -def build_update_request_initial( +def build_update_request( location_name: str, long_term_retention_server_name: str, long_term_retention_database_name: str, backup_name: str, subscription_id: str, - *, - json: Optional[_models.UpdateLongTermRetentionBackupParameters] = None, - content: Any = None, **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', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "longTermRetentionServerName": _SERIALIZER.url("long_term_retention_server_name", long_term_retention_server_name, 'str'), - "longTermRetentionDatabaseName": _SERIALIZER.url("long_term_retention_database_name", long_term_retention_database_name, 'str'), - "backupName": _SERIALIZER.url("backup_name", backup_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "longTermRetentionServerName": _SERIALIZER.url( + "long_term_retention_server_name", long_term_retention_server_name, "str" + ), + "longTermRetentionDatabaseName": _SERIALIZER.url( + "long_term_retention_database_name", long_term_retention_database_name, "str" + ), + "backupName": _SERIALIZER.url("backup_name", backup_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -138,37 +137,38 @@ 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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "longTermRetentionServerName": _SERIALIZER.url("long_term_retention_server_name", long_term_retention_server_name, 'str'), - "longTermRetentionDatabaseName": _SERIALIZER.url("long_term_retention_database_name", long_term_retention_database_name, 'str'), - "backupName": _SERIALIZER.url("backup_name", backup_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "longTermRetentionServerName": _SERIALIZER.url( + "long_term_retention_server_name", long_term_retention_server_name, "str" + ), + "longTermRetentionDatabaseName": _SERIALIZER.url( + "long_term_retention_database_name", long_term_retention_database_name, "str" + ), + "backupName": _SERIALIZER.url("backup_name", backup_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_request_initial( +def build_delete_request( location_name: str, long_term_retention_server_name: str, long_term_retention_database_name: str, @@ -178,28 +178,30 @@ def build_delete_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "longTermRetentionServerName": _SERIALIZER.url("long_term_retention_server_name", long_term_retention_server_name, 'str'), - "longTermRetentionDatabaseName": _SERIALIZER.url("long_term_retention_database_name", long_term_retention_database_name, 'str'), - "backupName": _SERIALIZER.url("backup_name", backup_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "longTermRetentionServerName": _SERIALIZER.url( + "long_term_retention_server_name", long_term_retention_server_name, "str" + ), + "longTermRetentionDatabaseName": _SERIALIZER.url( + "long_term_retention_database_name", long_term_retention_database_name, "str" + ), + "backupName": _SERIALIZER.url("backup_name", backup_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_database_request( @@ -215,37 +217,40 @@ def build_list_by_database_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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "longTermRetentionServerName": _SERIALIZER.url("long_term_retention_server_name", long_term_retention_server_name, 'str'), - "longTermRetentionDatabaseName": _SERIALIZER.url("long_term_retention_database_name", long_term_retention_database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "longTermRetentionServerName": _SERIALIZER.url( + "long_term_retention_server_name", long_term_retention_server_name, "str" + ), + "longTermRetentionDatabaseName": _SERIALIZER.url( + "long_term_retention_database_name", long_term_retention_database_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if only_latest_per_database is not None: - _params['onlyLatestPerDatabase'] = _SERIALIZER.query("only_latest_per_database", only_latest_per_database, 'bool') + _params["onlyLatestPerDatabase"] = _SERIALIZER.query( + "only_latest_per_database", only_latest_per_database, "bool" + ) if database_state is not None: - _params['databaseState'] = _SERIALIZER.query("database_state", database_state, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["databaseState"] = _SERIALIZER.query("database_state", database_state, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_location_request( @@ -259,35 +264,34 @@ def build_list_by_location_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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionBackups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionBackups", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if only_latest_per_database is not None: - _params['onlyLatestPerDatabase'] = _SERIALIZER.query("only_latest_per_database", only_latest_per_database, 'bool') + _params["onlyLatestPerDatabase"] = _SERIALIZER.query( + "only_latest_per_database", only_latest_per_database, "bool" + ) if database_state is not None: - _params['databaseState'] = _SERIALIZER.query("database_state", database_state, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["databaseState"] = _SERIALIZER.query("database_state", database_state, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_server_request( @@ -302,138 +306,131 @@ def build_list_by_server_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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionBackups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionBackups", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "longTermRetentionServerName": _SERIALIZER.url("long_term_retention_server_name", long_term_retention_server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "longTermRetentionServerName": _SERIALIZER.url( + "long_term_retention_server_name", long_term_retention_server_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if only_latest_per_database is not None: - _params['onlyLatestPerDatabase'] = _SERIALIZER.query("only_latest_per_database", only_latest_per_database, 'bool') + _params["onlyLatestPerDatabase"] = _SERIALIZER.query( + "only_latest_per_database", only_latest_per_database, "bool" + ) if database_state is not None: - _params['databaseState'] = _SERIALIZER.query("database_state", database_state, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["databaseState"] = _SERIALIZER.query("database_state", database_state, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_copy_by_resource_group_request_initial( +def build_copy_by_resource_group_request( resource_group_name: str, location_name: str, long_term_retention_server_name: str, long_term_retention_database_name: str, backup_name: str, subscription_id: str, - *, - json: Optional[_models.CopyLongTermRetentionBackupParameters] = None, - content: Any = None, **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', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "longTermRetentionServerName": _SERIALIZER.url("long_term_retention_server_name", long_term_retention_server_name, 'str'), - "longTermRetentionDatabaseName": _SERIALIZER.url("long_term_retention_database_name", long_term_retention_database_name, 'str'), - "backupName": _SERIALIZER.url("backup_name", backup_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "longTermRetentionServerName": _SERIALIZER.url( + "long_term_retention_server_name", long_term_retention_server_name, "str" + ), + "longTermRetentionDatabaseName": _SERIALIZER.url( + "long_term_retention_database_name", long_term_retention_database_name, "str" + ), + "backupName": _SERIALIZER.url("backup_name", backup_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) -def build_update_by_resource_group_request_initial( +def build_update_by_resource_group_request( resource_group_name: str, location_name: str, long_term_retention_server_name: str, long_term_retention_database_name: str, backup_name: str, subscription_id: str, - *, - json: Optional[_models.UpdateLongTermRetentionBackupParameters] = None, - content: Any = None, **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', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "longTermRetentionServerName": _SERIALIZER.url("long_term_retention_server_name", long_term_retention_server_name, 'str'), - "longTermRetentionDatabaseName": _SERIALIZER.url("long_term_retention_database_name", long_term_retention_database_name, 'str'), - "backupName": _SERIALIZER.url("backup_name", backup_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "longTermRetentionServerName": _SERIALIZER.url( + "long_term_retention_server_name", long_term_retention_server_name, "str" + ), + "longTermRetentionDatabaseName": _SERIALIZER.url( + "long_term_retention_database_name", long_term_retention_database_name, "str" + ), + "backupName": _SERIALIZER.url("backup_name", backup_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) def build_get_by_resource_group_request( @@ -448,38 +445,39 @@ def build_get_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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "longTermRetentionServerName": _SERIALIZER.url("long_term_retention_server_name", long_term_retention_server_name, 'str'), - "longTermRetentionDatabaseName": _SERIALIZER.url("long_term_retention_database_name", long_term_retention_database_name, 'str'), - "backupName": _SERIALIZER.url("backup_name", backup_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "longTermRetentionServerName": _SERIALIZER.url( + "long_term_retention_server_name", long_term_retention_server_name, "str" + ), + "longTermRetentionDatabaseName": _SERIALIZER.url( + "long_term_retention_database_name", long_term_retention_database_name, "str" + ), + "backupName": _SERIALIZER.url("backup_name", backup_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_by_resource_group_request_initial( +def build_delete_by_resource_group_request( resource_group_name: str, location_name: str, long_term_retention_server_name: str, @@ -490,29 +488,31 @@ def build_delete_by_resource_group_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "longTermRetentionServerName": _SERIALIZER.url("long_term_retention_server_name", long_term_retention_server_name, 'str'), - "longTermRetentionDatabaseName": _SERIALIZER.url("long_term_retention_database_name", long_term_retention_database_name, 'str'), - "backupName": _SERIALIZER.url("backup_name", backup_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "longTermRetentionServerName": _SERIALIZER.url( + "long_term_retention_server_name", long_term_retention_server_name, "str" + ), + "longTermRetentionDatabaseName": _SERIALIZER.url( + "long_term_retention_database_name", long_term_retention_database_name, "str" + ), + "backupName": _SERIALIZER.url("backup_name", backup_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_resource_group_database_request( @@ -529,38 +529,41 @@ def build_list_by_resource_group_database_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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "longTermRetentionServerName": _SERIALIZER.url("long_term_retention_server_name", long_term_retention_server_name, 'str'), - "longTermRetentionDatabaseName": _SERIALIZER.url("long_term_retention_database_name", long_term_retention_database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "longTermRetentionServerName": _SERIALIZER.url( + "long_term_retention_server_name", long_term_retention_server_name, "str" + ), + "longTermRetentionDatabaseName": _SERIALIZER.url( + "long_term_retention_database_name", long_term_retention_database_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if only_latest_per_database is not None: - _params['onlyLatestPerDatabase'] = _SERIALIZER.query("only_latest_per_database", only_latest_per_database, 'bool') + _params["onlyLatestPerDatabase"] = _SERIALIZER.query( + "only_latest_per_database", only_latest_per_database, "bool" + ) if database_state is not None: - _params['databaseState'] = _SERIALIZER.query("database_state", database_state, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["databaseState"] = _SERIALIZER.query("database_state", database_state, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_resource_group_location_request( @@ -575,36 +578,35 @@ def build_list_by_resource_group_location_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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionBackups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionBackups", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if only_latest_per_database is not None: - _params['onlyLatestPerDatabase'] = _SERIALIZER.query("only_latest_per_database", only_latest_per_database, 'bool') + _params["onlyLatestPerDatabase"] = _SERIALIZER.query( + "only_latest_per_database", only_latest_per_database, "bool" + ) if database_state is not None: - _params['databaseState'] = _SERIALIZER.query("database_state", database_state, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["databaseState"] = _SERIALIZER.query("database_state", database_state, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_resource_group_server_request( @@ -620,37 +622,39 @@ def build_list_by_resource_group_server_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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionBackups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionBackups", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "longTermRetentionServerName": _SERIALIZER.url("long_term_retention_server_name", long_term_retention_server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "longTermRetentionServerName": _SERIALIZER.url( + "long_term_retention_server_name", long_term_retention_server_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if only_latest_per_database is not None: - _params['onlyLatestPerDatabase'] = _SERIALIZER.query("only_latest_per_database", only_latest_per_database, 'bool') + _params["onlyLatestPerDatabase"] = _SERIALIZER.query( + "only_latest_per_database", only_latest_per_database, "bool" + ) if database_state is not None: - _params['databaseState'] = _SERIALIZER.query("database_state", database_state, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["databaseState"] = _SERIALIZER.query("database_state", database_state, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class LongTermRetentionBackupsOperations: """ @@ -671,31 +675,34 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - def _copy_initial( self, location_name: str, long_term_retention_server_name: str, long_term_retention_database_name: str, backup_name: str, - parameters: _models.CopyLongTermRetentionBackupParameters, + parameters: Union[_models.CopyLongTermRetentionBackupParameters, IO], **kwargs: Any ) -> Optional[_models.LongTermRetentionBackupOperationResult]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.LongTermRetentionBackupOperationResult]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.LongTermRetentionBackupOperationResult]] - _json = self._serialize.body(parameters, 'CopyLongTermRetentionBackupParameters') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "CopyLongTermRetentionBackupParameters") - request = build_copy_request_initial( + request = build_copy_request( location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, long_term_retention_database_name=long_term_retention_database_name, @@ -704,7 +711,8 @@ def _copy_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._copy_initial.metadata['url'], + content=_content, + template_url=self._copy_initial.metadata["url"], headers=_headers, params=_params, ) @@ -712,10 +720,9 @@ def _copy_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -724,17 +731,16 @@ def _copy_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('LongTermRetentionBackupOperationResult', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackupOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _copy_initial.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy"} # type: ignore - + _copy_initial.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy"} # type: ignore - @distributed_trace + @overload def begin_copy( self, location_name: str, @@ -742,23 +748,108 @@ def begin_copy( long_term_retention_database_name: str, backup_name: str, parameters: _models.CopyLongTermRetentionBackupParameters, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.LongTermRetentionBackupOperationResult]: """Copy an existing long term retention backup. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :param parameters: The parameters needed for long term retention copy request. + :param parameters: The parameters needed for long term retention copy request. Required. :type parameters: ~azure.mgmt.sql.models.CopyLongTermRetentionBackupParameters - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 LongTermRetentionBackupOperationResult or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_copy( + self, + location_name: str, + long_term_retention_server_name: str, + long_term_retention_database_name: str, + backup_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.LongTermRetentionBackupOperationResult]: + """Copy an existing long term retention backup. + + :param location_name: The location of the database. Required. + :type location_name: str + :param long_term_retention_server_name: The name of the server. Required. + :type long_term_retention_server_name: str + :param long_term_retention_database_name: The name of the database. Required. + :type long_term_retention_database_name: str + :param backup_name: The backup name. Required. + :type backup_name: str + :param parameters: The parameters needed for long term retention copy request. Required. + :type parameters: IO + :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 LongTermRetentionBackupOperationResult or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_copy( + self, + location_name: str, + long_term_retention_server_name: str, + long_term_retention_database_name: str, + backup_name: str, + parameters: Union[_models.CopyLongTermRetentionBackupParameters, IO], + **kwargs: Any + ) -> LROPoller[_models.LongTermRetentionBackupOperationResult]: + """Copy an existing long term retention backup. + + :param location_name: The location of the database. Required. + :type location_name: str + :param long_term_retention_server_name: The name of the server. Required. + :type long_term_retention_server_name: str + :param long_term_retention_database_name: The name of the database. Required. + :type long_term_retention_database_name: str + :param backup_name: The backup name. Required. + :type backup_name: str + :param parameters: The parameters needed for long term retention copy request. Is either a + model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.CopyLongTermRetentionBackupParameters 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 @@ -771,20 +862,17 @@ def begin_copy( the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupOperationResult] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupOperationResult] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._copy_initial( # type: ignore location_name=location_name, @@ -794,39 +882,35 @@ def begin_copy( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('LongTermRetentionBackupOperationResult', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackupOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_copy.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy"} # type: ignore + begin_copy.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy"} # type: ignore def _update_initial( self, @@ -834,24 +918,28 @@ def _update_initial( long_term_retention_server_name: str, long_term_retention_database_name: str, backup_name: str, - parameters: _models.UpdateLongTermRetentionBackupParameters, + parameters: Union[_models.UpdateLongTermRetentionBackupParameters, IO], **kwargs: Any ) -> Optional[_models.LongTermRetentionBackupOperationResult]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.LongTermRetentionBackupOperationResult]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.LongTermRetentionBackupOperationResult]] - _json = self._serialize.body(parameters, 'UpdateLongTermRetentionBackupParameters') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "UpdateLongTermRetentionBackupParameters") - request = build_update_request_initial( + request = build_update_request( location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, long_term_retention_database_name=long_term_retention_database_name, @@ -860,7 +948,8 @@ def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -868,10 +957,9 @@ def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -880,17 +968,16 @@ def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('LongTermRetentionBackupOperationResult', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackupOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update"} # type: ignore + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update"} # type: ignore - - @distributed_trace + @overload def begin_update( self, location_name: str, @@ -898,23 +985,108 @@ def begin_update( long_term_retention_database_name: str, backup_name: str, parameters: _models.UpdateLongTermRetentionBackupParameters, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.LongTermRetentionBackupOperationResult]: """Updates an existing long term retention backup. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :param parameters: The requested backup resource state. + :param parameters: The requested backup resource state. Required. :type parameters: ~azure.mgmt.sql.models.UpdateLongTermRetentionBackupParameters - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 LongTermRetentionBackupOperationResult or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_update( + self, + location_name: str, + long_term_retention_server_name: str, + long_term_retention_database_name: str, + backup_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.LongTermRetentionBackupOperationResult]: + """Updates an existing long term retention backup. + + :param location_name: The location of the database. Required. + :type location_name: str + :param long_term_retention_server_name: The name of the server. Required. + :type long_term_retention_server_name: str + :param long_term_retention_database_name: The name of the database. Required. + :type long_term_retention_database_name: str + :param backup_name: The backup name. Required. + :type backup_name: str + :param parameters: The requested backup resource state. Required. + :type parameters: IO + :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 LongTermRetentionBackupOperationResult or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_update( + self, + location_name: str, + long_term_retention_server_name: str, + long_term_retention_database_name: str, + backup_name: str, + parameters: Union[_models.UpdateLongTermRetentionBackupParameters, IO], + **kwargs: Any + ) -> LROPoller[_models.LongTermRetentionBackupOperationResult]: + """Updates an existing long term retention backup. + + :param location_name: The location of the database. Required. + :type location_name: str + :param long_term_retention_server_name: The name of the server. Required. + :type long_term_retention_server_name: str + :param long_term_retention_database_name: The name of the database. Required. + :type long_term_retention_database_name: str + :param backup_name: The backup name. Required. + :type backup_name: str + :param parameters: The requested backup resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.UpdateLongTermRetentionBackupParameters 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 @@ -927,20 +1099,17 @@ def begin_update( the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupOperationResult] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupOperationResult] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._update_initial( # type: ignore location_name=location_name, @@ -950,39 +1119,35 @@ def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('LongTermRetentionBackupOperationResult', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackupOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update"} # type: ignore @distributed_trace def get( @@ -995,34 +1160,28 @@ def get( ) -> _models.LongTermRetentionBackup: """Gets a long term retention backup. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: LongTermRetentionBackup, or the result of cls(response) + :return: LongTermRetentionBackup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.LongTermRetentionBackup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackup] - request = build_get_request( location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, @@ -1030,7 +1189,7 @@ def get( backup_name=backup_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -1038,25 +1197,23 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('LongTermRetentionBackup', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements self, @@ -1066,26 +1223,23 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements backup_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, long_term_retention_database_name=long_term_retention_database_name, backup_name=backup_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1093,10 +1247,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1106,11 +1259,10 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements + def begin_delete( self, location_name: str, long_term_retention_server_name: str, @@ -1120,17 +1272,14 @@ def begin_delete( # pylint: disable=inconsistent-return-statements ) -> LROPoller[None]: """Deletes a long term retention backup. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1141,19 +1290,16 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore location_name=location_name, @@ -1161,37 +1307,33 @@ def begin_delete( # pylint: disable=inconsistent-return-statements long_term_retention_database_name=long_term_retention_database_name, backup_name=backup_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore @distributed_trace def list_by_database( @@ -1202,52 +1344,48 @@ def list_by_database( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> Iterable[_models.LongTermRetentionBackupListResult]: + ) -> Iterable["_models.LongTermRetentionBackup"]: """Lists all long term retention backups for a database. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LongTermRetentionBackupListResult or the result of + :return: An iterator like instance of either LongTermRetentionBackup or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, long_term_retention_database_name=long_term_retention_database_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -1255,19 +1393,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - location_name=location_name, - long_term_retention_server_name=long_term_retention_server_name, - long_term_retention_database_name=long_term_retention_database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1283,10 +1409,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1296,11 +1420,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups"} # type: ignore @distributed_trace def list_by_location( @@ -1309,46 +1431,42 @@ def list_by_location( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> Iterable[_models.LongTermRetentionBackupListResult]: + ) -> Iterable["_models.LongTermRetentionBackup"]: """Lists the long term retention backups for a given location. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LongTermRetentionBackupListResult or the result of + :return: An iterator like instance of either LongTermRetentionBackup or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_location_request( location_name=location_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_location.metadata['url'], + api_version=api_version, + template_url=self.list_by_location.metadata["url"], headers=_headers, params=_params, ) @@ -1356,17 +1474,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_location_request( - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1382,10 +1490,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1395,11 +1501,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionBackups"} # type: ignore + list_by_location.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionBackups"} # type: ignore @distributed_trace def list_by_server( @@ -1409,49 +1513,45 @@ def list_by_server( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> Iterable[_models.LongTermRetentionBackupListResult]: + ) -> Iterable["_models.LongTermRetentionBackup"]: """Lists the long term retention backups for a given server. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LongTermRetentionBackupListResult or the result of + :return: An iterator like instance of either LongTermRetentionBackup or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_server.metadata['url'], + api_version=api_version, + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -1459,18 +1559,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - location_name=location_name, - long_term_retention_server_name=long_term_retention_server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1486,10 +1575,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1499,11 +1586,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionBackups"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionBackups"} # type: ignore def _copy_by_resource_group_initial( self, @@ -1512,24 +1597,28 @@ def _copy_by_resource_group_initial( long_term_retention_server_name: str, long_term_retention_database_name: str, backup_name: str, - parameters: _models.CopyLongTermRetentionBackupParameters, + parameters: Union[_models.CopyLongTermRetentionBackupParameters, IO], **kwargs: Any ) -> Optional[_models.LongTermRetentionBackupOperationResult]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.LongTermRetentionBackupOperationResult]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.LongTermRetentionBackupOperationResult]] - _json = self._serialize.body(parameters, 'CopyLongTermRetentionBackupParameters') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "CopyLongTermRetentionBackupParameters") - request = build_copy_by_resource_group_request_initial( + request = build_copy_by_resource_group_request( resource_group_name=resource_group_name, location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, @@ -1539,7 +1628,8 @@ def _copy_by_resource_group_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._copy_by_resource_group_initial.metadata['url'], + content=_content, + template_url=self._copy_by_resource_group_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1547,10 +1637,9 @@ def _copy_by_resource_group_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1559,17 +1648,16 @@ def _copy_by_resource_group_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('LongTermRetentionBackupOperationResult', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackupOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _copy_by_resource_group_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy"} # type: ignore + _copy_by_resource_group_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy"} # type: ignore - - @distributed_trace + @overload def begin_copy_by_resource_group( self, resource_group_name: str, @@ -1578,26 +1666,119 @@ def begin_copy_by_resource_group( long_term_retention_database_name: str, backup_name: str, parameters: _models.CopyLongTermRetentionBackupParameters, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.LongTermRetentionBackupOperationResult]: """Copy an existing long term retention backup to a different server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :param parameters: The parameters needed for long term retention copy request. + :param parameters: The parameters needed for long term retention copy request. Required. :type parameters: ~azure.mgmt.sql.models.CopyLongTermRetentionBackupParameters - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 LongTermRetentionBackupOperationResult or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_copy_by_resource_group( + self, + resource_group_name: str, + location_name: str, + long_term_retention_server_name: str, + long_term_retention_database_name: str, + backup_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.LongTermRetentionBackupOperationResult]: + """Copy an existing long term retention backup to a different server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param location_name: The location of the database. Required. + :type location_name: str + :param long_term_retention_server_name: The name of the server. Required. + :type long_term_retention_server_name: str + :param long_term_retention_database_name: The name of the database. Required. + :type long_term_retention_database_name: str + :param backup_name: The backup name. Required. + :type backup_name: str + :param parameters: The parameters needed for long term retention copy request. Required. + :type parameters: IO + :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 LongTermRetentionBackupOperationResult or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_copy_by_resource_group( + self, + resource_group_name: str, + location_name: str, + long_term_retention_server_name: str, + long_term_retention_database_name: str, + backup_name: str, + parameters: Union[_models.CopyLongTermRetentionBackupParameters, IO], + **kwargs: Any + ) -> LROPoller[_models.LongTermRetentionBackupOperationResult]: + """Copy an existing long term retention backup to a different server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param location_name: The location of the database. Required. + :type location_name: str + :param long_term_retention_server_name: The name of the server. Required. + :type long_term_retention_server_name: str + :param long_term_retention_database_name: The name of the database. Required. + :type long_term_retention_database_name: str + :param backup_name: The backup name. Required. + :type backup_name: str + :param parameters: The parameters needed for long term retention copy request. Is either a + model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.CopyLongTermRetentionBackupParameters 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 @@ -1610,20 +1791,17 @@ def begin_copy_by_resource_group( the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupOperationResult] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupOperationResult] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._copy_by_resource_group_initial( # type: ignore resource_group_name=resource_group_name, @@ -1634,39 +1812,35 @@ def begin_copy_by_resource_group( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('LongTermRetentionBackupOperationResult', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackupOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_copy_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy"} # type: ignore + begin_copy_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/copy"} # type: ignore def _update_by_resource_group_initial( self, @@ -1675,24 +1849,28 @@ def _update_by_resource_group_initial( long_term_retention_server_name: str, long_term_retention_database_name: str, backup_name: str, - parameters: _models.UpdateLongTermRetentionBackupParameters, + parameters: Union[_models.UpdateLongTermRetentionBackupParameters, IO], **kwargs: Any ) -> Optional[_models.LongTermRetentionBackupOperationResult]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.LongTermRetentionBackupOperationResult]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.LongTermRetentionBackupOperationResult]] - _json = self._serialize.body(parameters, 'UpdateLongTermRetentionBackupParameters') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "UpdateLongTermRetentionBackupParameters") - request = build_update_by_resource_group_request_initial( + request = build_update_by_resource_group_request( resource_group_name=resource_group_name, location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, @@ -1702,7 +1880,8 @@ def _update_by_resource_group_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_by_resource_group_initial.metadata['url'], + content=_content, + template_url=self._update_by_resource_group_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1710,10 +1889,9 @@ def _update_by_resource_group_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1722,17 +1900,16 @@ def _update_by_resource_group_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('LongTermRetentionBackupOperationResult', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackupOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_by_resource_group_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update"} # type: ignore + _update_by_resource_group_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update"} # type: ignore - - @distributed_trace + @overload def begin_update_by_resource_group( self, resource_group_name: str, @@ -1741,26 +1918,28 @@ def begin_update_by_resource_group( long_term_retention_database_name: str, backup_name: str, parameters: _models.UpdateLongTermRetentionBackupParameters, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.LongTermRetentionBackupOperationResult]: """Updates an existing long term retention backup. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :param parameters: The requested backup resource state. + :param parameters: The requested backup resource state. Required. :type parameters: ~azure.mgmt.sql.models.UpdateLongTermRetentionBackupParameters - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -1773,20 +1952,108 @@ def begin_update_by_resource_group( the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_update_by_resource_group( + self, + resource_group_name: str, + location_name: str, + long_term_retention_server_name: str, + long_term_retention_database_name: str, + backup_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.LongTermRetentionBackupOperationResult]: + """Updates an existing long term retention backup. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param location_name: The location of the database. Required. + :type location_name: str + :param long_term_retention_server_name: The name of the server. Required. + :type long_term_retention_server_name: str + :param long_term_retention_database_name: The name of the database. Required. + :type long_term_retention_database_name: str + :param backup_name: The backup name. Required. + :type backup_name: str + :param parameters: The requested backup resource state. Required. + :type parameters: IO + :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 LongTermRetentionBackupOperationResult or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_update_by_resource_group( + self, + resource_group_name: str, + location_name: str, + long_term_retention_server_name: str, + long_term_retention_database_name: str, + backup_name: str, + parameters: Union[_models.UpdateLongTermRetentionBackupParameters, IO], + **kwargs: Any + ) -> LROPoller[_models.LongTermRetentionBackupOperationResult]: + """Updates an existing long term retention backup. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param location_name: The location of the database. Required. + :type location_name: str + :param long_term_retention_server_name: The name of the server. Required. + :type long_term_retention_server_name: str + :param long_term_retention_database_name: The name of the database. Required. + :type long_term_retention_database_name: str + :param backup_name: The backup name. Required. + :type backup_name: str + :param parameters: The requested backup resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.UpdateLongTermRetentionBackupParameters 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. + :return: An instance of LROPoller that returns either LongTermRetentionBackupOperationResult or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LongTermRetentionBackupOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupOperationResult] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupOperationResult] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._update_by_resource_group_initial( # type: ignore resource_group_name=resource_group_name, @@ -1797,39 +2064,35 @@ def begin_update_by_resource_group( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('LongTermRetentionBackupOperationResult', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackupOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update"} # type: ignore + begin_update_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}/update"} # type: ignore @distributed_trace def get_by_resource_group( @@ -1844,36 +2107,30 @@ def get_by_resource_group( """Gets a long term retention backup. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: LongTermRetentionBackup, or the result of cls(response) + :return: LongTermRetentionBackup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.LongTermRetentionBackup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackup] - request = build_get_by_resource_group_request( resource_group_name=resource_group_name, location_name=location_name, @@ -1882,7 +2139,7 @@ def get_by_resource_group( backup_name=backup_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get_by_resource_group.metadata['url'], + template_url=self.get_by_resource_group.metadata["url"], headers=_headers, params=_params, ) @@ -1890,25 +2147,23 @@ def get_by_resource_group( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('LongTermRetentionBackup', pipeline_response) + deserialized = self._deserialize("LongTermRetentionBackup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore - + get_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore def _delete_by_resource_group_initial( # pylint: disable=inconsistent-return-statements self, @@ -1919,19 +2174,16 @@ def _delete_by_resource_group_initial( # pylint: disable=inconsistent-return-st backup_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_by_resource_group_request_initial( + request = build_delete_by_resource_group_request( resource_group_name=resource_group_name, location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, @@ -1939,7 +2191,7 @@ def _delete_by_resource_group_initial( # pylint: disable=inconsistent-return-st backup_name=backup_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_by_resource_group_initial.metadata['url'], + template_url=self._delete_by_resource_group_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1947,10 +2199,9 @@ def _delete_by_resource_group_initial( # pylint: disable=inconsistent-return-st request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1960,11 +2211,10 @@ def _delete_by_resource_group_initial( # pylint: disable=inconsistent-return-st if cls: return cls(pipeline_response, None, {}) - _delete_by_resource_group_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore - + _delete_by_resource_group_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore @distributed_trace - def begin_delete_by_resource_group( # pylint: disable=inconsistent-return-statements + def begin_delete_by_resource_group( self, resource_group_name: str, location_name: str, @@ -1976,19 +2226,16 @@ def begin_delete_by_resource_group( # pylint: disable=inconsistent-return-state """Deletes a long term retention backup. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1999,19 +2246,16 @@ def begin_delete_by_resource_group( # pylint: disable=inconsistent-return-state 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_by_resource_group_initial( # type: ignore resource_group_name=resource_group_name, @@ -2020,37 +2264,33 @@ def begin_delete_by_resource_group( # pylint: disable=inconsistent-return-state long_term_retention_database_name=long_term_retention_database_name, backup_name=backup_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_delete_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore + begin_delete_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups/{backupName}"} # type: ignore @distributed_trace def list_by_resource_group_database( @@ -2062,56 +2302,52 @@ def list_by_resource_group_database( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> Iterable[_models.LongTermRetentionBackupListResult]: + ) -> Iterable["_models.LongTermRetentionBackup"]: """Lists all long term retention backups for a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str - :param long_term_retention_database_name: The name of the database. + :param long_term_retention_database_name: The name of the database. Required. :type long_term_retention_database_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LongTermRetentionBackupListResult or the result of + :return: An iterator like instance of either LongTermRetentionBackup or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_database_request( resource_group_name=resource_group_name, location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, long_term_retention_database_name=long_term_retention_database_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_resource_group_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_resource_group_database.metadata["url"], headers=_headers, params=_params, ) @@ -2119,20 +2355,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_database_request( - resource_group_name=resource_group_name, - location_name=location_name, - long_term_retention_server_name=long_term_retention_server_name, - long_term_retention_database_name=long_term_retention_database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -2148,10 +2371,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -2161,11 +2382,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_resource_group_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups"} # type: ignore + list_by_resource_group_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionDatabases/{longTermRetentionDatabaseName}/longTermRetentionBackups"} # type: ignore @distributed_trace def list_by_resource_group_location( @@ -2175,50 +2394,46 @@ def list_by_resource_group_location( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> Iterable[_models.LongTermRetentionBackupListResult]: + ) -> Iterable["_models.LongTermRetentionBackup"]: """Lists the long term retention backups for a given location. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LongTermRetentionBackupListResult or the result of + :return: An iterator like instance of either LongTermRetentionBackup or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_location_request( resource_group_name=resource_group_name, location_name=location_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_resource_group_location.metadata['url'], + api_version=api_version, + template_url=self.list_by_resource_group_location.metadata["url"], headers=_headers, params=_params, ) @@ -2226,18 +2441,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_location_request( - resource_group_name=resource_group_name, - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -2253,10 +2457,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -2266,11 +2468,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_resource_group_location.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionBackups"} # type: ignore + list_by_resource_group_location.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionBackups"} # type: ignore @distributed_trace def list_by_resource_group_server( @@ -2281,53 +2481,49 @@ def list_by_resource_group_server( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> Iterable[_models.LongTermRetentionBackupListResult]: + ) -> Iterable["_models.LongTermRetentionBackup"]: """Lists the long term retention backups for a given server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param long_term_retention_server_name: The name of the server. + :param long_term_retention_server_name: The name of the server. Required. :type long_term_retention_server_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LongTermRetentionBackupListResult or the result of + :return: An iterator like instance of either LongTermRetentionBackup or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_server_request( resource_group_name=resource_group_name, location_name=location_name, long_term_retention_server_name=long_term_retention_server_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_resource_group_server.metadata['url'], + api_version=api_version, + template_url=self.list_by_resource_group_server.metadata["url"], headers=_headers, params=_params, ) @@ -2335,19 +2531,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_server_request( - resource_group_name=resource_group_name, - location_name=location_name, - long_term_retention_server_name=long_term_retention_server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -2363,10 +2547,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -2376,8 +2558,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_resource_group_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionBackups"} # type: ignore + list_by_resource_group_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionServers/{longTermRetentionServerName}/longTermRetentionBackups"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_long_term_retention_managed_instance_backups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_long_term_retention_managed_instance_backups_operations.py index 70e97826232ac..62c7337f37211 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_long_term_retention_managed_instance_backups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_long_term_retention_managed_instance_backups_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( location_name: str, managed_instance_name: str, @@ -40,37 +47,34 @@ 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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "backupName": _SERIALIZER.url("backup_name", backup_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "backupName": _SERIALIZER.url("backup_name", backup_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_request_initial( +def build_delete_request( location_name: str, managed_instance_name: str, database_name: str, @@ -80,28 +84,26 @@ def build_delete_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "backupName": _SERIALIZER.url("backup_name", backup_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "backupName": _SERIALIZER.url("backup_name", backup_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_database_request( @@ -117,37 +119,36 @@ def build_list_by_database_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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if only_latest_per_database is not None: - _params['onlyLatestPerDatabase'] = _SERIALIZER.query("only_latest_per_database", only_latest_per_database, 'bool') + _params["onlyLatestPerDatabase"] = _SERIALIZER.query( + "only_latest_per_database", only_latest_per_database, "bool" + ) if database_state is not None: - _params['databaseState'] = _SERIALIZER.query("database_state", database_state, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["databaseState"] = _SERIALIZER.query("database_state", database_state, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_instance_request( @@ -162,36 +163,35 @@ def build_list_by_instance_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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionManagedInstanceBackups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionManagedInstanceBackups", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if only_latest_per_database is not None: - _params['onlyLatestPerDatabase'] = _SERIALIZER.query("only_latest_per_database", only_latest_per_database, 'bool') + _params["onlyLatestPerDatabase"] = _SERIALIZER.query( + "only_latest_per_database", only_latest_per_database, "bool" + ) if database_state is not None: - _params['databaseState'] = _SERIALIZER.query("database_state", database_state, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["databaseState"] = _SERIALIZER.query("database_state", database_state, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_location_request( @@ -205,35 +205,34 @@ def build_list_by_location_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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstanceBackups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstanceBackups", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if only_latest_per_database is not None: - _params['onlyLatestPerDatabase'] = _SERIALIZER.query("only_latest_per_database", only_latest_per_database, 'bool') + _params["onlyLatestPerDatabase"] = _SERIALIZER.query( + "only_latest_per_database", only_latest_per_database, "bool" + ) if database_state is not None: - _params['databaseState'] = _SERIALIZER.query("database_state", database_state, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["databaseState"] = _SERIALIZER.query("database_state", database_state, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_by_resource_group_request( @@ -248,38 +247,35 @@ def build_get_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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "backupName": _SERIALIZER.url("backup_name", backup_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "backupName": _SERIALIZER.url("backup_name", backup_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_by_resource_group_request_initial( +def build_delete_by_resource_group_request( resource_group_name: str, location_name: str, managed_instance_name: str, @@ -290,29 +286,27 @@ def build_delete_by_resource_group_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "backupName": _SERIALIZER.url("backup_name", backup_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "backupName": _SERIALIZER.url("backup_name", backup_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_resource_group_database_request( @@ -329,38 +323,37 @@ def build_list_by_resource_group_database_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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if only_latest_per_database is not None: - _params['onlyLatestPerDatabase'] = _SERIALIZER.query("only_latest_per_database", only_latest_per_database, 'bool') + _params["onlyLatestPerDatabase"] = _SERIALIZER.query( + "only_latest_per_database", only_latest_per_database, "bool" + ) if database_state is not None: - _params['databaseState'] = _SERIALIZER.query("database_state", database_state, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["databaseState"] = _SERIALIZER.query("database_state", database_state, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_resource_group_instance_request( @@ -376,37 +369,36 @@ def build_list_by_resource_group_instance_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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionManagedInstanceBackups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionManagedInstanceBackups", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if only_latest_per_database is not None: - _params['onlyLatestPerDatabase'] = _SERIALIZER.query("only_latest_per_database", only_latest_per_database, 'bool') + _params["onlyLatestPerDatabase"] = _SERIALIZER.query( + "only_latest_per_database", only_latest_per_database, "bool" + ) if database_state is not None: - _params['databaseState'] = _SERIALIZER.query("database_state", database_state, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["databaseState"] = _SERIALIZER.query("database_state", database_state, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_resource_group_location_request( @@ -421,36 +413,36 @@ def build_list_by_resource_group_location_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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstanceBackups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstanceBackups", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if only_latest_per_database is not None: - _params['onlyLatestPerDatabase'] = _SERIALIZER.query("only_latest_per_database", only_latest_per_database, 'bool') + _params["onlyLatestPerDatabase"] = _SERIALIZER.query( + "only_latest_per_database", only_latest_per_database, "bool" + ) if database_state is not None: - _params['databaseState'] = _SERIALIZER.query("database_state", database_state, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["databaseState"] = _SERIALIZER.query("database_state", database_state, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class LongTermRetentionManagedInstanceBackupsOperations: """ @@ -471,46 +463,34 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( - self, - location_name: str, - managed_instance_name: str, - database_name: str, - backup_name: str, - **kwargs: Any + self, location_name: str, managed_instance_name: str, database_name: str, backup_name: str, **kwargs: Any ) -> _models.ManagedInstanceLongTermRetentionBackup: """Gets a long term retention backup for a managed database. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the managed database. + :param database_name: The name of the managed database. Required. :type database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceLongTermRetentionBackup, or the result of cls(response) + :return: ManagedInstanceLongTermRetentionBackup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackup] - request = build_get_request( location_name=location_name, managed_instance_name=managed_instance_name, @@ -518,7 +498,7 @@ def get( backup_name=backup_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -526,54 +506,44 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceLongTermRetentionBackup', pipeline_response) + deserialized = self._deserialize("ManagedInstanceLongTermRetentionBackup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - location_name: str, - managed_instance_name: str, - database_name: str, - backup_name: str, - **kwargs: Any + self, location_name: str, managed_instance_name: str, database_name: str, backup_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( location_name=location_name, managed_instance_name=managed_instance_name, database_name=database_name, backup_name=backup_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -581,10 +551,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -594,31 +563,22 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - location_name: str, - managed_instance_name: str, - database_name: str, - backup_name: str, - **kwargs: Any + def begin_delete( + self, location_name: str, managed_instance_name: str, database_name: str, backup_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes a long term retention backup. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the managed database. + :param database_name: The name of the managed database. Required. :type database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -629,19 +589,16 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore location_name=location_name, @@ -649,37 +606,33 @@ def begin_delete( # pylint: disable=inconsistent-return-statements database_name=database_name, backup_name=backup_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore @distributed_trace def list_by_database( @@ -690,53 +643,49 @@ def list_by_database( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> Iterable[_models.ManagedInstanceLongTermRetentionBackupListResult]: + ) -> Iterable["_models.ManagedInstanceLongTermRetentionBackup"]: """Lists all long term retention backups for a managed database. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the managed database. + :param database_name: The name of the managed database. Required. :type database_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackupListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackup or the + result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( location_name=location_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -744,19 +693,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - location_name=location_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -772,10 +709,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -785,11 +720,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups"} # type: ignore @distributed_trace def list_by_instance( @@ -799,50 +732,46 @@ def list_by_instance( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> Iterable[_models.ManagedInstanceLongTermRetentionBackupListResult]: + ) -> Iterable["_models.ManagedInstanceLongTermRetentionBackup"]: """Lists the long term retention backups for a given managed instance. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackupListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackup or the + result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( location_name=location_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_instance.metadata['url'], + api_version=api_version, + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -850,18 +779,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - location_name=location_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -877,10 +795,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -890,11 +806,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionManagedInstanceBackups"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionManagedInstanceBackups"} # type: ignore @distributed_trace def list_by_location( @@ -903,47 +817,43 @@ def list_by_location( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> Iterable[_models.ManagedInstanceLongTermRetentionBackupListResult]: + ) -> Iterable["_models.ManagedInstanceLongTermRetentionBackup"]: """Lists the long term retention backups for managed databases in a given location. - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackupListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackup or the + result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_location_request( location_name=location_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_location.metadata['url'], + api_version=api_version, + template_url=self.list_by_location.metadata["url"], headers=_headers, params=_params, ) @@ -951,17 +861,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_location_request( - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -977,10 +877,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -990,11 +888,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstanceBackups"} # type: ignore + list_by_location.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstanceBackups"} # type: ignore @distributed_trace def get_by_resource_group( @@ -1009,36 +905,30 @@ def get_by_resource_group( """Gets a long term retention backup for a managed database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the managed database. + :param database_name: The name of the managed database. Required. :type database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceLongTermRetentionBackup, or the result of cls(response) + :return: ManagedInstanceLongTermRetentionBackup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackup] - request = build_get_by_resource_group_request( resource_group_name=resource_group_name, location_name=location_name, @@ -1047,7 +937,7 @@ def get_by_resource_group( backup_name=backup_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get_by_resource_group.metadata['url'], + template_url=self.get_by_resource_group.metadata["url"], headers=_headers, params=_params, ) @@ -1055,25 +945,23 @@ def get_by_resource_group( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceLongTermRetentionBackup', pipeline_response) + deserialized = self._deserialize("ManagedInstanceLongTermRetentionBackup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore - + get_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore def _delete_by_resource_group_initial( # pylint: disable=inconsistent-return-statements self, @@ -1084,19 +972,16 @@ def _delete_by_resource_group_initial( # pylint: disable=inconsistent-return-st backup_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_by_resource_group_request_initial( + request = build_delete_by_resource_group_request( resource_group_name=resource_group_name, location_name=location_name, managed_instance_name=managed_instance_name, @@ -1104,7 +989,7 @@ def _delete_by_resource_group_initial( # pylint: disable=inconsistent-return-st backup_name=backup_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_by_resource_group_initial.metadata['url'], + template_url=self._delete_by_resource_group_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1112,10 +997,9 @@ def _delete_by_resource_group_initial( # pylint: disable=inconsistent-return-st request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1125,11 +1009,10 @@ def _delete_by_resource_group_initial( # pylint: disable=inconsistent-return-st if cls: return cls(pipeline_response, None, {}) - _delete_by_resource_group_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore - + _delete_by_resource_group_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore @distributed_trace - def begin_delete_by_resource_group( # pylint: disable=inconsistent-return-statements + def begin_delete_by_resource_group( self, resource_group_name: str, location_name: str, @@ -1141,19 +1024,16 @@ def begin_delete_by_resource_group( # pylint: disable=inconsistent-return-state """Deletes a long term retention backup. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the managed database. + :param database_name: The name of the managed database. Required. :type database_name: str - :param backup_name: The backup name. + :param backup_name: The backup name. Required. :type backup_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1164,19 +1044,16 @@ def begin_delete_by_resource_group( # pylint: disable=inconsistent-return-state 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_by_resource_group_initial( # type: ignore resource_group_name=resource_group_name, @@ -1185,37 +1062,33 @@ def begin_delete_by_resource_group( # pylint: disable=inconsistent-return-state database_name=database_name, backup_name=backup_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_delete_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore + begin_delete_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups/{backupName}"} # type: ignore @distributed_trace def list_by_resource_group_database( @@ -1227,57 +1100,53 @@ def list_by_resource_group_database( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> Iterable[_models.ManagedInstanceLongTermRetentionBackupListResult]: + ) -> Iterable["_models.ManagedInstanceLongTermRetentionBackup"]: """Lists all long term retention backups for a managed database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the managed database. + :param database_name: The name of the managed database. Required. :type database_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackupListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackup or the + result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_database_request( resource_group_name=resource_group_name, location_name=location_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_resource_group_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_resource_group_database.metadata["url"], headers=_headers, params=_params, ) @@ -1285,20 +1154,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_database_request( - resource_group_name=resource_group_name, - location_name=location_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1314,10 +1170,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1327,11 +1181,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_resource_group_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups"} # type: ignore + list_by_resource_group_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionDatabases/{databaseName}/longTermRetentionManagedInstanceBackups"} # type: ignore @distributed_trace def list_by_resource_group_instance( @@ -1342,54 +1194,50 @@ def list_by_resource_group_instance( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> Iterable[_models.ManagedInstanceLongTermRetentionBackupListResult]: + ) -> Iterable["_models.ManagedInstanceLongTermRetentionBackup"]: """Lists the long term retention backups for a given managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackupListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackup or the + result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_instance_request( resource_group_name=resource_group_name, location_name=location_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_resource_group_instance.metadata['url'], + api_version=api_version, + template_url=self.list_by_resource_group_instance.metadata["url"], headers=_headers, params=_params, ) @@ -1397,19 +1245,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_instance_request( - resource_group_name=resource_group_name, - location_name=location_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1425,10 +1261,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1438,11 +1272,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_resource_group_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionManagedInstanceBackups"} # type: ignore + list_by_resource_group_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstances/{managedInstanceName}/longTermRetentionManagedInstanceBackups"} # type: ignore @distributed_trace def list_by_resource_group_location( @@ -1452,51 +1284,47 @@ def list_by_resource_group_location( only_latest_per_database: Optional[bool] = None, database_state: Optional[Union[str, "_models.DatabaseState"]] = None, **kwargs: Any - ) -> Iterable[_models.ManagedInstanceLongTermRetentionBackupListResult]: + ) -> Iterable["_models.ManagedInstanceLongTermRetentionBackup"]: """Lists the long term retention backups for managed databases in a given location. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The location of the database. + :param location_name: The location of the database. Required. :type location_name: str :param only_latest_per_database: Whether or not to only get the latest backup for each database. Default value is None. :type only_latest_per_database: bool :param database_state: Whether to query against just live databases, just deleted databases, or - all databases. Default value is None. + all databases. Known values are: "All", "Live", and "Deleted". Default value is None. :type database_state: str or ~azure.mgmt.sql.models.DatabaseState - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackupListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstanceLongTermRetentionBackup or the + result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionBackup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionBackupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_location_request( resource_group_name=resource_group_name, location_name=location_name, subscription_id=self._config.subscription_id, - api_version=api_version, only_latest_per_database=only_latest_per_database, database_state=database_state, - template_url=self.list_by_resource_group_location.metadata['url'], + api_version=api_version, + template_url=self.list_by_resource_group_location.metadata["url"], headers=_headers, params=_params, ) @@ -1504,18 +1332,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_location_request( - resource_group_name=resource_group_name, - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - only_latest_per_database=only_latest_per_database, - database_state=database_state, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1531,10 +1348,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1544,8 +1359,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_resource_group_location.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstanceBackups"} # type: ignore + list_by_resource_group_location.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/longTermRetentionManagedInstanceBackups"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_long_term_retention_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_long_term_retention_policies_operations.py index fdfe99be76334..9c1e38c725c97 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_long_term_retention_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_long_term_retention_policies_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -40,122 +47,105 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "policyName": _SERIALIZER.url("policy_name", policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "policyName": _SERIALIZER.url("policy_name", policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, server_name: str, database_name: str, policy_name: Union[str, "_models.LongTermRetentionPolicyName"], subscription_id: str, - *, - json: Optional[_models.LongTermRetentionPolicy] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "policyName": _SERIALIZER.url("policy_name", policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "policyName": _SERIALIZER.url("policy_name", policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_database_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class LongTermRetentionPoliciesOperations: """ @@ -176,7 +166,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -189,34 +178,28 @@ def get( """Gets a database's long term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be Default. + :param policy_name: The policy name. Should always be Default. "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.LongTermRetentionPolicyName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: LongTermRetentionPolicy, or the result of cls(response) + :return: LongTermRetentionPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.LongTermRetentionPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -224,7 +207,7 @@ def get( policy_name=policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -232,25 +215,23 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('LongTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("LongTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore def _create_or_update_initial( self, @@ -258,24 +239,28 @@ def _create_or_update_initial( server_name: str, database_name: str, policy_name: Union[str, "_models.LongTermRetentionPolicyName"], - parameters: _models.LongTermRetentionPolicy, + parameters: Union[_models.LongTermRetentionPolicy, IO], **kwargs: Any ) -> Optional[_models.LongTermRetentionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.LongTermRetentionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.LongTermRetentionPolicy]] - _json = self._serialize.body(parameters, 'LongTermRetentionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "LongTermRetentionPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -284,7 +269,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -292,10 +278,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -304,17 +289,16 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('LongTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("LongTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, @@ -322,24 +306,68 @@ def begin_create_or_update( database_name: str, policy_name: Union[str, "_models.LongTermRetentionPolicyName"], parameters: _models.LongTermRetentionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.LongTermRetentionPolicy]: """Sets a database's long term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be Default. + :param policy_name: The policy name. Should always be Default. "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.LongTermRetentionPolicyName - :param parameters: The long term retention policy info. + :param parameters: The long term retention policy info. Required. :type parameters: ~azure.mgmt.sql.models.LongTermRetentionPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 LongTermRetentionPolicy or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LongTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + policy_name: Union[str, "_models.LongTermRetentionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.LongTermRetentionPolicy]: + """Sets a database's long term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be Default. "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.LongTermRetentionPolicyName + :param parameters: The long term retention policy info. Required. + :type parameters: IO + :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 @@ -351,20 +379,58 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either LongTermRetentionPolicy or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LongTermRetentionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + policy_name: Union[str, "_models.LongTermRetentionPolicyName"], + parameters: Union[_models.LongTermRetentionPolicy, IO], + **kwargs: Any + ) -> LROPoller[_models.LongTermRetentionPolicy]: + """Sets a database's long term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be Default. "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.LongTermRetentionPolicyName + :param parameters: The long term retention policy info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.LongTermRetentionPolicy 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. + :return: An instance of LROPoller that returns either LongTermRetentionPolicy or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.LongTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -374,86 +440,74 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('LongTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("LongTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.LongTermRetentionPolicyListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.LongTermRetentionPolicy"]: """Gets a database's long term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LongTermRetentionPolicyListResult or the result of + :return: An iterator like instance of either LongTermRetentionPolicy or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LongTermRetentionPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LongTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LongTermRetentionPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LongTermRetentionPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -461,17 +515,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -487,10 +531,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -500,8 +542,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_maintenance_window_options_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_maintenance_window_options_operations.py index df6822af12cd5..e111fafa83a64 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_maintenance_window_options_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_maintenance_window_options_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse from azure.core.rest import HttpRequest @@ -19,13 +23,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -38,34 +45,34 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindowOptions/current") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindowOptions/current", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['maintenanceWindowOptionsName'] = _SERIALIZER.query("maintenance_window_options_name", maintenance_window_options_name, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["maintenanceWindowOptionsName"] = _SERIALIZER.query( + "maintenance_window_options_name", maintenance_window_options_name, "str" + ) + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + class MaintenanceWindowOptionsOperations: """ @@ -86,7 +93,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -99,42 +105,37 @@ def get( """Gets a list of available maintenance windows. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the database to get maintenance windows options for. + Required. :type database_name: str - :param maintenance_window_options_name: Maintenance window options name. + :param maintenance_window_options_name: Maintenance window options name. Required. :type maintenance_window_options_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: MaintenanceWindowOptions, or the result of cls(response) + :return: MaintenanceWindowOptions or the result of cls(response) :rtype: ~azure.mgmt.sql.models.MaintenanceWindowOptions - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.MaintenanceWindowOptions] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.MaintenanceWindowOptions] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, maintenance_window_options_name=maintenance_window_options_name, - template_url=self.get.metadata['url'], + api_version=api_version, + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -142,22 +143,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('MaintenanceWindowOptions', pipeline_response) + deserialized = self._deserialize("MaintenanceWindowOptions", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindowOptions/current"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindowOptions/current"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_maintenance_windows_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_maintenance_windows_operations.py index 889abb4956b1a..1e4393623e122 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_maintenance_windows_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_maintenance_windows_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse from azure.core.rest import HttpRequest @@ -19,13 +23,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -38,34 +45,31 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindows/current") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindows/current", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['maintenanceWindowName'] = _SERIALIZER.query("maintenance_window_name", maintenance_window_name, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["maintenanceWindowName"] = _SERIALIZER.query("maintenance_window_name", maintenance_window_name, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( @@ -75,43 +79,37 @@ def build_create_or_update_request( subscription_id: str, *, maintenance_window_name: str, - json: Optional[_models.MaintenanceWindows] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindows/current") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindows/current", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['maintenanceWindowName'] = _SERIALIZER.query("maintenance_window_name", maintenance_window_name, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["maintenanceWindowName"] = _SERIALIZER.query("maintenance_window_name", maintenance_window_name, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + class MaintenanceWindowsOperations: """ @@ -132,7 +130,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -145,42 +142,36 @@ def get( """Gets maintenance windows settings for a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database to get maintenance windows for. + :param database_name: The name of the database to get maintenance windows for. Required. :type database_name: str - :param maintenance_window_name: Maintenance window name. + :param maintenance_window_name: Maintenance window name. Required. :type maintenance_window_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: MaintenanceWindows, or the result of cls(response) + :return: MaintenanceWindows or the result of cls(response) :rtype: ~azure.mgmt.sql.models.MaintenanceWindows - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.MaintenanceWindows] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.MaintenanceWindows] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, maintenance_window_name=maintenance_window_name, - template_url=self.get.metadata['url'], + api_version=api_version, + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -188,27 +179,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('MaintenanceWindows', pipeline_response) + deserialized = self._deserialize("MaintenanceWindows", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindows/current"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindows/current"} # type: ignore - @distributed_trace + @overload def create_or_update( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, @@ -216,53 +205,126 @@ def create_or_update( # pylint: disable=inconsistent-return-statements database_name: str, maintenance_window_name: str, parameters: _models.MaintenanceWindows, + *, + content_type: str = "application/json", **kwargs: Any ) -> None: """Sets maintenance windows settings for a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database to set maintenance windows for. + :param database_name: The name of the database to set maintenance windows for. Required. :type database_name: str - :param maintenance_window_name: Maintenance window name. + :param maintenance_window_name: Maintenance window name. Required. :type maintenance_window_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.MaintenanceWindows - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + def create_or_update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + server_name: str, + database_name: str, + maintenance_window_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> None: + """Sets maintenance windows settings for a database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database to set maintenance windows for. Required. + :type database_name: str + :param maintenance_window_name: Maintenance window name. Required. + :type maintenance_window_name: str + :param parameters: Required. + :type parameters: IO + :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: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + server_name: str, + database_name: str, + maintenance_window_name: str, + parameters: Union[_models.MaintenanceWindows, IO], + **kwargs: Any + ) -> None: + """Sets maintenance windows settings for a database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database to set maintenance windows for. Required. + :type database_name: str + :param maintenance_window_name: Maintenance window name. Required. + :type maintenance_window_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.MaintenanceWindows 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 + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'MaintenanceWindows') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "MaintenanceWindows") request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, + maintenance_window_name=maintenance_window_name, api_version=api_version, content_type=content_type, - maintenance_window_name=maintenance_window_name, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -270,10 +332,9 @@ def create_or_update( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -283,5 +344,4 @@ def create_or_update( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindows/current"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/maintenanceWindows/current"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_backup_short_term_retention_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_backup_short_term_retention_policies_operations.py index 637ae6361ba13..9c22d9d4cad98 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_backup_short_term_retention_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_backup_short_term_retention_policies_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, managed_instance_name: str, @@ -40,171 +47,146 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "policyName": _SERIALIZER.url("policy_name", policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "policyName": _SERIALIZER.url("policy_name", policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, managed_instance_name: str, database_name: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], subscription_id: str, - *, - json: Optional[_models.ManagedBackupShortTermRetentionPolicy] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "policyName": _SERIALIZER.url("policy_name", policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "policyName": _SERIALIZER.url("policy_name", policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_update_request_initial( +def build_update_request( resource_group_name: str, managed_instance_name: str, database_name: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], subscription_id: str, - *, - json: Optional[_models.ManagedBackupShortTermRetentionPolicy] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "policyName": _SERIALIZER.url("policy_name", policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "policyName": _SERIALIZER.url("policy_name", policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_database_request( - resource_group_name: str, - managed_instance_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedBackupShortTermRetentionPoliciesOperations: """ @@ -225,7 +207,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -238,34 +219,28 @@ def get( """Gets a managed database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. + :param policy_name: The policy name. "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedBackupShortTermRetentionPolicy, or the result of cls(response) + :return: ManagedBackupShortTermRetentionPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -273,7 +248,7 @@ def get( policy_name=policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -281,25 +256,23 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore def _create_or_update_initial( self, @@ -307,24 +280,28 @@ def _create_or_update_initial( managed_instance_name: str, database_name: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], - parameters: _models.ManagedBackupShortTermRetentionPolicy, + parameters: Union[_models.ManagedBackupShortTermRetentionPolicy, IO], **kwargs: Any ) -> Optional[_models.ManagedBackupShortTermRetentionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedBackupShortTermRetentionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedBackupShortTermRetentionPolicy]] - _json = self._serialize.body(parameters, 'ManagedBackupShortTermRetentionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedBackupShortTermRetentionPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, @@ -333,7 +310,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -341,10 +319,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -353,17 +330,16 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, @@ -371,24 +347,69 @@ def begin_create_or_update( database_name: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], parameters: _models.ManagedBackupShortTermRetentionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ManagedBackupShortTermRetentionPolicy]: """Updates a managed database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be "default". + :param policy_name: The policy name. Should always be "default". "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName - :param parameters: The short term retention policy info. + :param parameters: The short term retention policy info. Required. :type parameters: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ManagedBackupShortTermRetentionPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedBackupShortTermRetentionPolicy]: + """Updates a managed database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Required. + :type parameters: IO + :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 @@ -401,20 +422,59 @@ def begin_create_or_update( the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], + parameters: Union[_models.ManagedBackupShortTermRetentionPolicy, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedBackupShortTermRetentionPolicy]: + """Updates a managed database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy 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. + :return: An instance of LROPoller that returns either ManagedBackupShortTermRetentionPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -424,39 +484,35 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore def _update_initial( self, @@ -464,24 +520,28 @@ def _update_initial( managed_instance_name: str, database_name: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], - parameters: _models.ManagedBackupShortTermRetentionPolicy, + parameters: Union[_models.ManagedBackupShortTermRetentionPolicy, IO], **kwargs: Any ) -> Optional[_models.ManagedBackupShortTermRetentionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedBackupShortTermRetentionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedBackupShortTermRetentionPolicy]] - _json = self._serialize.body(parameters, 'ManagedBackupShortTermRetentionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedBackupShortTermRetentionPolicy") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, @@ -490,7 +550,8 @@ def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -498,10 +559,9 @@ def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -510,17 +570,16 @@ def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - @distributed_trace + @overload def begin_update( self, resource_group_name: str, @@ -528,24 +587,111 @@ def begin_update( database_name: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], parameters: _models.ManagedBackupShortTermRetentionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ManagedBackupShortTermRetentionPolicy]: """Updates a managed database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be "default". + :param policy_name: The policy name. Should always be "default". "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName - :param parameters: The short term retention policy info. + :param parameters: The short term retention policy info. Required. :type parameters: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ManagedBackupShortTermRetentionPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedBackupShortTermRetentionPolicy]: + """Updates a managed database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Required. + :type parameters: IO + :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 ManagedBackupShortTermRetentionPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], + parameters: Union[_models.ManagedBackupShortTermRetentionPolicy, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedBackupShortTermRetentionPolicy]: + """Updates a managed database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy 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 @@ -558,20 +704,17 @@ def begin_update( the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -581,87 +724,75 @@ def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.ManagedBackupShortTermRetentionPolicyListResult]: + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedBackupShortTermRetentionPolicy"]: """Gets a managed database's short term retention policy list. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedBackupShortTermRetentionPolicyListResult or - the result of cls(response) + :return: An iterator like instance of either ManagedBackupShortTermRetentionPolicy or the + result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -669,17 +800,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -695,10 +816,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -708,8 +827,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupShortTermRetentionPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_advanced_threat_protection_settings_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_advanced_threat_protection_settings_operations.py new file mode 100644 index 0000000000000..b00faa946857c --- /dev/null +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_advanced_threat_protection_settings_operations.py @@ -0,0 +1,479 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.rest import 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 .._serialization import Serializer +from .._vendor import _convert_request, _format_url_section + +T = TypeVar("T") +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False + + +def build_list_by_database_request( + resource_group_name: str, managed_instance_name: str, database_name: str, subscription_id: str, **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", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/advancedThreatProtectionSettings", + ) # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_get_request( + resource_group_name: str, + managed_instance_name: str, + database_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + subscription_id: str, + **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", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}", + ) # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "advancedThreatProtectionName": _SERIALIZER.url( + "advanced_threat_protection_name", advanced_threat_protection_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, + managed_instance_name: str, + database_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + subscription_id: str, + **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", "2022-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}", + ) # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "advancedThreatProtectionName": _SERIALIZER.url( + "advanced_threat_protection_name", advanced_threat_protection_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +class ManagedDatabaseAdvancedThreatProtectionSettingsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.mgmt.sql.SqlManagementClient`'s + :attr:`managed_database_advanced_threat_protection_settings` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs): + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace + def list_by_database( + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedDatabaseAdvancedThreatProtection"]: + """Gets a list of managed database's Advanced Threat Protection states. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ManagedDatabaseAdvancedThreatProtection or the + result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedDatabaseAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _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: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseAdvancedThreatProtectionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_database_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_database.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + else: + request = HttpRequest("GET", next_link) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("ManagedDatabaseAdvancedThreatProtectionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/advancedThreatProtectionSettings"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + **kwargs: Any + ) -> _models.ManagedDatabaseAdvancedThreatProtection: + """Gets a managed database's Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ManagedDatabaseAdvancedThreatProtection or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedDatabaseAdvancedThreatProtection + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + _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: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseAdvancedThreatProtection] + + request = build_get_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + advanced_threat_protection_name=advanced_threat_protection_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 + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("ManagedDatabaseAdvancedThreatProtection", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore + + @overload + def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: _models.ManagedDatabaseAdvancedThreatProtection, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.ManagedDatabaseAdvancedThreatProtection: + """Creates or updates a managed database's Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The managed database Advanced Threat Protection state. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseAdvancedThreatProtection + :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: ManagedDatabaseAdvancedThreatProtection or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedDatabaseAdvancedThreatProtection + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.ManagedDatabaseAdvancedThreatProtection: + """Creates or updates a managed database's Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The managed database Advanced Threat Protection state. Required. + :type parameters: IO + :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: ManagedDatabaseAdvancedThreatProtection or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedDatabaseAdvancedThreatProtection + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: Union[_models.ManagedDatabaseAdvancedThreatProtection, IO], + **kwargs: Any + ) -> _models.ManagedDatabaseAdvancedThreatProtection: + """Creates or updates a managed database's Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The managed database Advanced Threat Protection state. Is either a model + type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseAdvancedThreatProtection 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 + :return: ManagedDatabaseAdvancedThreatProtection or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedDatabaseAdvancedThreatProtection + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_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: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseAdvancedThreatProtection] + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedDatabaseAdvancedThreatProtection") + + request = build_create_or_update_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + advanced_threat_protection_name=advanced_threat_protection_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + 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 + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + 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("ManagedDatabaseAdvancedThreatProtection", pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize("ManagedDatabaseAdvancedThreatProtection", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_columns_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_columns_operations.py index 1760c4a72bc1c..5bdd0d9a7924e 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_columns_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_columns_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, List, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_database_request( resource_group_name: str, managed_instance_name: str, @@ -43,43 +50,40 @@ def build_list_by_database_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/columns") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/columns", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if schema is not None: - _params['schema'] = [_SERIALIZER.query("schema", q, 'str') if q is not None else '' for q in schema] + _params["schema"] = [_SERIALIZER.query("schema", q, "str") if q is not None else "" for q in schema] if table is not None: - _params['table'] = [_SERIALIZER.query("table", q, 'str') if q is not None else '' for q in table] + _params["table"] = [_SERIALIZER.query("table", q, "str") if q is not None else "" for q in table] if column is not None: - _params['column'] = [_SERIALIZER.query("column", q, 'str') if q is not None else '' for q in column] + _params["column"] = [_SERIALIZER.query("column", q, "str") if q is not None else "" for q in column] if order_by is not None: - _params['orderBy'] = [_SERIALIZER.query("order_by", q, 'str') if q is not None else '' for q in order_by] + _params["orderBy"] = [_SERIALIZER.query("order_by", q, "str") if q is not None else "" for q in order_by] if skiptoken is not None: - _params['$skiptoken'] = _SERIALIZER.query("skiptoken", skiptoken, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$skiptoken"] = _SERIALIZER.query("skiptoken", skiptoken, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_table_request( @@ -96,37 +100,34 @@ def build_list_by_table_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "tableName": _SERIALIZER.url("table_name", table_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "tableName": _SERIALIZER.url("table_name", table_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if filter is not None: - _params['$filter'] = _SERIALIZER.query("filter", filter, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$filter"] = _SERIALIZER.query("filter", filter, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -142,36 +143,34 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "tableName": _SERIALIZER.url("table_name", table_name, 'str'), - "columnName": _SERIALIZER.url("column_name", column_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "tableName": _SERIALIZER.url("table_name", table_name, "str"), + "columnName": _SERIALIZER.url("column_name", column_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedDatabaseColumnsOperations: """ @@ -192,7 +191,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( self, @@ -205,61 +203,56 @@ def list_by_database( order_by: Optional[List[str]] = None, skiptoken: Optional[str] = None, **kwargs: Any - ) -> Iterable[_models.DatabaseColumnListResult]: + ) -> Iterable["_models.DatabaseColumn"]: """List managed database columns. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema: Default value is None. + :param schema: Default value is None. :type schema: list[str] - :param table: Default value is None. + :param table: Default value is None. :type table: list[str] - :param column: Default value is None. + :param column: Default value is None. :type column: list[str] - :param order_by: Default value is None. + :param order_by: Default value is None. :type order_by: list[str] :param skiptoken: An opaque token that identifies a starting point in the collection. Default value is None. :type skiptoken: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseColumnListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseColumnListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseColumn or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseColumn] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseColumnListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseColumnListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, schema=schema, table=table, column=column, order_by=order_by, skiptoken=skiptoken, - template_url=self.list_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -267,22 +260,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - schema=schema, - table=table, - column=column, - order_by=order_by, - skiptoken=skiptoken, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -298,10 +276,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -311,11 +287,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/columns"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/columns"} # type: ignore @distributed_trace def list_by_table( @@ -327,45 +301,40 @@ def list_by_table( table_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable[_models.DatabaseColumnListResult]: + ) -> Iterable["_models.DatabaseColumn"]: """List managed database columns. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseColumnListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseColumnListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseColumn or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseColumn] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseColumnListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseColumnListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_table_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -373,9 +342,9 @@ def prepare_request(next_link=None): schema_name=schema_name, table_name=table_name, subscription_id=self._config.subscription_id, - api_version=api_version, filter=filter, - template_url=self.list_by_table.metadata['url'], + api_version=api_version, + template_url=self.list_by_table.metadata["url"], headers=_headers, params=_params, ) @@ -383,20 +352,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_table_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - schema_name=schema_name, - table_name=table_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -412,10 +368,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -425,11 +379,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_table.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns"} # type: ignore + list_by_table.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns"} # type: ignore @distributed_trace def get( @@ -445,38 +397,32 @@ def get( """Get managed database column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseColumn, or the result of cls(response) + :return: DatabaseColumn or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseColumn - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseColumn] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseColumn] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -486,7 +432,7 @@ def get( column_name=column_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -494,22 +440,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseColumn', pipeline_response) + deserialized = self._deserialize("DatabaseColumn", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_queries_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_queries_operations.py index 5992b34b08c23..86657b04660bb 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_queries_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_queries_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, managed_instance_name: str, @@ -38,34 +45,31 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/queries/{queryId}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/queries/{queryId}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "queryId": _SERIALIZER.url("query_id", query_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "queryId": _SERIALIZER.url("query_id", query_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_query_request( @@ -83,40 +87,38 @@ def build_list_by_query_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/queries/{queryId}/statistics") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/queries/{queryId}/statistics", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "queryId": _SERIALIZER.url("query_id", query_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "queryId": _SERIALIZER.url("query_id", query_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if start_time is not None: - _params['startTime'] = _SERIALIZER.query("start_time", start_time, 'str') + _params["startTime"] = _SERIALIZER.query("start_time", start_time, "str") if end_time is not None: - _params['endTime'] = _SERIALIZER.query("end_time", end_time, 'str') + _params["endTime"] = _SERIALIZER.query("end_time", end_time, "str") if interval is not None: - _params['interval'] = _SERIALIZER.query("interval", interval, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["interval"] = _SERIALIZER.query("interval", interval, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedDatabaseQueriesOperations: """ @@ -137,47 +139,35 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - query_id: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, database_name: str, query_id: str, **kwargs: Any ) -> _models.ManagedInstanceQuery: """Get query by query id. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param query_id: + :param query_id: Required. :type query_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceQuery, or the result of cls(response) + :return: ManagedInstanceQuery or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceQuery - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceQuery] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceQuery] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -185,7 +175,7 @@ def get( query_id=query_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -193,25 +183,23 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceQuery', pipeline_response) + deserialized = self._deserialize("ManagedInstanceQuery", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/queries/{queryId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/queries/{queryId}"} # type: ignore @distributed_trace def list_by_query( @@ -224,58 +212,53 @@ def list_by_query( end_time: Optional[str] = None, interval: Optional[Union[str, "_models.QueryTimeGrainType"]] = None, **kwargs: Any - ) -> Iterable[_models.ManagedInstanceQueryStatistics]: + ) -> Iterable["_models.QueryStatistics"]: """Get query execution statistics by query id. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param query_id: + :param query_id: Required. :type query_id: str :param start_time: Start time for observed period. Default value is None. :type start_time: str :param end_time: End time for observed period. Default value is None. :type end_time: str - :param interval: The time step to be used to summarize the metric values. Default value is - None. + :param interval: The time step to be used to summarize the metric values. Known values are: + "PT1H" and "P1D". Default value is None. :type interval: str or ~azure.mgmt.sql.models.QueryTimeGrainType - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceQueryStatistics or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceQueryStatistics] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either QueryStatistics or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.QueryStatistics] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceQueryStatistics] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceQueryStatistics] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_query_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, query_id=query_id, subscription_id=self._config.subscription_id, - api_version=api_version, start_time=start_time, end_time=end_time, interval=interval, - template_url=self.list_by_query.metadata['url'], + api_version=api_version, + template_url=self.list_by_query.metadata["url"], headers=_headers, params=_params, ) @@ -283,21 +266,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_query_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - query_id=query_id, - subscription_id=self._config.subscription_id, - api_version=api_version, - start_time=start_time, - end_time=end_time, - interval=interval, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -313,10 +282,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -326,8 +293,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_query.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/queries/{queryId}/statistics"} # type: ignore + list_by_query.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/queries/{queryId}/statistics"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_recommended_sensitivity_labels_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_recommended_sensitivity_labels_operations.py index a53d3fed803c7..7566593a8a546 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_recommended_sensitivity_labels_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_recommended_sensitivity_labels_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse from azure.core.rest import HttpRequest @@ -19,55 +23,47 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_update_request( - resource_group_name: str, - managed_instance_name: str, - database_name: str, - subscription_id: str, - *, - json: Optional[_models.RecommendedSensitivityLabelUpdateList] = None, - content: Any = None, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/recommendedSensitivityLabels") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/recommendedSensitivityLabels", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) + class ManagedDatabaseRecommendedSensitivityLabelsOperations: """ @@ -88,48 +84,113 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace + @overload def update( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, managed_instance_name: str, database_name: str, parameters: _models.RecommendedSensitivityLabelUpdateList, + *, + content_type: str = "application/json", **kwargs: Any ) -> None: """Update recommended sensitivity labels states of a given database using an operations batch. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.RecommendedSensitivityLabelUpdateList - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + def update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> None: + """Update recommended sensitivity labels states of a given database using an operations batch. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Required. + :type parameters: IO + :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: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.RecommendedSensitivityLabelUpdateList, IO], + **kwargs: Any + ) -> None: + """Update recommended sensitivity labels states of a given database using an operations batch. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.RecommendedSensitivityLabelUpdateList 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 + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'RecommendedSensitivityLabelUpdateList') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "RecommendedSensitivityLabelUpdateList") request = build_update_request( resource_group_name=resource_group_name, @@ -139,7 +200,8 @@ def update( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -147,10 +209,9 @@ def update( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -160,5 +221,4 @@ def update( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/recommendedSensitivityLabels"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/recommendedSensitivityLabels"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_restore_details_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_restore_details_operations.py index 8575e2af1dd88..d5e7646b8c847 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_restore_details_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_restore_details_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Optional, TypeVar, Union -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse from azure.core.rest import HttpRequest @@ -19,13 +23,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, managed_instance_name: str, @@ -37,34 +44,32 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/restoreDetails/{restoreDetailsName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/restoreDetails/{restoreDetailsName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "restoreDetailsName": _SERIALIZER.url("restore_details_name", restore_details_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "restoreDetailsName": _SERIALIZER.url("restore_details_name", restore_details_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedDatabaseRestoreDetailsOperations: """ @@ -85,7 +90,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -98,34 +102,28 @@ def get( """Gets managed database restore details. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param restore_details_name: The name of the restore details to retrieve. + :param restore_details_name: The name of the restore details to retrieve. "Default" Required. :type restore_details_name: str or ~azure.mgmt.sql.models.RestoreDetailsName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedDatabaseRestoreDetailsResult, or the result of cls(response) + :return: ManagedDatabaseRestoreDetailsResult or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedDatabaseRestoreDetailsResult - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabaseRestoreDetailsResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseRestoreDetailsResult] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -133,7 +131,7 @@ def get( restore_details_name=restore_details_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -141,22 +139,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedDatabaseRestoreDetailsResult', pipeline_response) + deserialized = self._deserialize("ManagedDatabaseRestoreDetailsResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/restoreDetails/{restoreDetailsName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/restoreDetails/{restoreDetailsName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_schemas_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_schemas_operations.py index f2a5133ef7f45..9810bcedddba3 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_schemas_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_schemas_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_database_request( resource_group_name: str, managed_instance_name: str, @@ -39,35 +46,32 @@ def build_list_by_database_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if filter is not None: - _params['$filter'] = _SERIALIZER.query("filter", filter, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$filter"] = _SERIALIZER.query("filter", filter, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -81,34 +85,32 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedDatabaseSchemasOperations: """ @@ -129,7 +131,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( self, @@ -138,49 +139,44 @@ def list_by_database( database_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable[_models.DatabaseSchemaListResult]: + ) -> Iterable["_models.DatabaseSchema"]: """List managed database schemas. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseSchemaListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseSchemaListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseSchema or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseSchema] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseSchemaListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseSchemaListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, filter=filter, - template_url=self.list_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -188,18 +184,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -215,10 +200,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -228,52 +211,39 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - schema_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, database_name: str, schema_name: str, **kwargs: Any ) -> _models.DatabaseSchema: """Get managed database schema. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseSchema, or the result of cls(response) + :return: DatabaseSchema or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseSchema - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseSchema] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseSchema] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -281,7 +251,7 @@ def get( schema_name=schema_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -289,22 +259,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseSchema', pipeline_response) + deserialized = self._deserialize("DatabaseSchema", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_security_alert_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_security_alert_policies_operations.py index f865f6ab501f5..f48b161eac933 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_security_alert_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_security_alert_policies_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, managed_instance_name: str, @@ -38,34 +45,31 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "securityAlertPolicyName": _SERIALIZER.url("security_alert_policy_name", security_alert_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "securityAlertPolicyName": _SERIALIZER.url("security_alert_policy_name", security_alert_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( @@ -74,86 +78,72 @@ def build_create_or_update_request( database_name: str, security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], subscription_id: str, - *, - json: Optional[_models.ManagedDatabaseSecurityAlertPolicy] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "securityAlertPolicyName": _SERIALIZER.url("security_alert_policy_name", security_alert_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "securityAlertPolicyName": _SERIALIZER.url("security_alert_policy_name", security_alert_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_database_request( - resource_group_name: str, - managed_instance_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedDatabaseSecurityAlertPoliciesOperations: """ @@ -174,7 +164,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -187,35 +176,29 @@ def get( """Gets a managed database's security alert policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the managed database for which the security alert policy is - defined. + defined. Required. :type database_name: str - :param security_alert_policy_name: The name of the security alert policy. + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedDatabaseSecurityAlertPolicy, or the result of cls(response) + :return: ManagedDatabaseSecurityAlertPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedDatabaseSecurityAlertPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabaseSecurityAlertPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseSecurityAlertPolicy] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -223,7 +206,7 @@ def get( security_alert_policy_name=security_alert_policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -231,27 +214,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedDatabaseSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ManagedDatabaseSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, @@ -259,43 +240,118 @@ def create_or_update( database_name: str, security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], parameters: _models.ManagedDatabaseSecurityAlertPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.ManagedDatabaseSecurityAlertPolicy: """Creates or updates a database's security alert policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the managed database for which the security alert policy is - defined. + defined. Required. :type database_name: str - :param security_alert_policy_name: The name of the security alert policy. + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName - :param parameters: The database security alert policy. + :param parameters: The database security alert policy. Required. :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseSecurityAlertPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: ManagedDatabaseSecurityAlertPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedDatabaseSecurityAlertPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.ManagedDatabaseSecurityAlertPolicy: + """Creates or updates a database's security alert policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the managed database for which the security alert policy is + defined. Required. + :type database_name: str + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. + :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName + :param parameters: The database security alert policy. Required. + :type parameters: IO + :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: ManagedDatabaseSecurityAlertPolicy or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedDatabaseSecurityAlertPolicy + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], + parameters: Union[_models.ManagedDatabaseSecurityAlertPolicy, IO], + **kwargs: Any + ) -> _models.ManagedDatabaseSecurityAlertPolicy: + """Creates or updates a database's security alert policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the managed database for which the security alert policy is + defined. Required. + :type database_name: str + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. + :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName + :param parameters: The database security alert policy. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseSecurityAlertPolicy 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 - :return: ManagedDatabaseSecurityAlertPolicy, or the result of cls(response) + :return: ManagedDatabaseSecurityAlertPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedDatabaseSecurityAlertPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabaseSecurityAlertPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseSecurityAlertPolicy] - _json = self._serialize.body(parameters, 'ManagedDatabaseSecurityAlertPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedDatabaseSecurityAlertPolicy") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -306,7 +362,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -314,10 +371,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -325,67 +381,57 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('ManagedDatabaseSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ManagedDatabaseSecurityAlertPolicy", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedDatabaseSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ManagedDatabaseSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.ManagedDatabaseSecurityAlertPolicyListResult]: + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedDatabaseSecurityAlertPolicy"]: """Gets a list of managed database's security alert policies. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the managed database for which the security alert policies - are defined. + are defined. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedDatabaseSecurityAlertPolicyListResult or - the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedDatabaseSecurityAlertPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedDatabaseSecurityAlertPolicy or the result + of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedDatabaseSecurityAlertPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabaseSecurityAlertPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseSecurityAlertPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -393,17 +439,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -419,10 +455,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -432,8 +466,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityAlertPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_security_events_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_security_events_operations.py index 6f4677165bc70..0dcabfd34b749 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_security_events_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_security_events_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_database_request( resource_group_name: str, managed_instance_name: str, @@ -42,41 +49,39 @@ def build_list_by_database_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityEvents") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityEvents", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if filter is not None: - _params['$filter'] = _SERIALIZER.query("filter", filter, 'str') + _params["$filter"] = _SERIALIZER.query("filter", filter, "str") if skip is not None: - _params['$skip'] = _SERIALIZER.query("skip", skip, 'int') + _params["$skip"] = _SERIALIZER.query("skip", skip, "int") if top is not None: - _params['$top'] = _SERIALIZER.query("top", top, 'int') + _params["$top"] = _SERIALIZER.query("top", top, "int") if skiptoken is not None: - _params['$skiptoken'] = _SERIALIZER.query("skiptoken", skiptoken, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$skiptoken"] = _SERIALIZER.query("skiptoken", skiptoken, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedDatabaseSecurityEventsOperations: """ @@ -97,7 +102,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( self, @@ -109,16 +113,16 @@ def list_by_database( top: Optional[int] = None, skiptoken: Optional[str] = None, **kwargs: Any - ) -> Iterable[_models.SecurityEventCollection]: + ) -> Iterable["_models.SecurityEvent"]: """Gets a list of security events. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the managed database for which the security events are - retrieved. + retrieved. Required. :type database_name: str :param filter: An OData filter expression that filters elements in the collection. Default value is None. @@ -130,39 +134,34 @@ def list_by_database( :param skiptoken: An opaque token that identifies a starting point in the collection. Default value is None. :type skiptoken: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SecurityEventCollection or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SecurityEventCollection] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SecurityEvent or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SecurityEvent] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SecurityEventCollection] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SecurityEventCollection] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, filter=filter, skip=skip, top=top, skiptoken=skiptoken, - template_url=self.list_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -170,21 +169,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - filter=filter, - skip=skip, - top=top, - skiptoken=skiptoken, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -200,10 +185,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -213,8 +196,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityEvents"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/securityEvents"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_sensitivity_labels_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_sensitivity_labels_operations.py index 4be8130980626..1b6865dfe3ee3 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_sensitivity_labels_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_sensitivity_labels_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, managed_instance_name: str, @@ -41,37 +48,34 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "tableName": _SERIALIZER.url("table_name", table_name, 'str'), - "columnName": _SERIALIZER.url("column_name", column_name, 'str'), - "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "tableName": _SERIALIZER.url("table_name", table_name, "str"), + "columnName": _SERIALIZER.url("column_name", column_name, "str"), + "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( @@ -82,51 +86,43 @@ def build_create_or_update_request( table_name: str, column_name: str, subscription_id: str, - *, - json: Optional[_models.SensitivityLabel] = None, - content: Any = None, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "current") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "current") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "tableName": _SERIALIZER.url("table_name", table_name, 'str'), - "columnName": _SERIALIZER.url("column_name", column_name, 'str'), - "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "tableName": _SERIALIZER.url("table_name", table_name, "str"), + "columnName": _SERIALIZER.url("column_name", column_name, "str"), + "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_delete_request( @@ -141,32 +137,30 @@ def build_delete_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "current") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "current") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "tableName": _SERIALIZER.url("table_name", table_name, 'str'), - "columnName": _SERIALIZER.url("column_name", column_name, 'str'), - "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "tableName": _SERIALIZER.url("table_name", table_name, "str"), + "columnName": _SERIALIZER.url("column_name", column_name, "str"), + "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_disable_recommendation_request( @@ -181,32 +175,30 @@ def build_disable_recommendation_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "recommended") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "recommended") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/disable") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/disable", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "tableName": _SERIALIZER.url("table_name", table_name, 'str'), - "columnName": _SERIALIZER.url("column_name", column_name, 'str'), - "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "tableName": _SERIALIZER.url("table_name", table_name, "str"), + "columnName": _SERIALIZER.url("column_name", column_name, "str"), + "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) def build_enable_recommendation_request( @@ -221,32 +213,30 @@ def build_enable_recommendation_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "recommended") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "recommended") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/enable") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/enable", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "tableName": _SERIALIZER.url("table_name", table_name, 'str'), - "columnName": _SERIALIZER.url("column_name", column_name, 'str'), - "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "tableName": _SERIALIZER.url("table_name", table_name, "str"), + "columnName": _SERIALIZER.url("column_name", column_name, "str"), + "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) def build_list_current_by_database_request( @@ -263,83 +253,68 @@ def build_list_current_by_database_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/currentSensitivityLabels") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/currentSensitivityLabels", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if skip_token is not None: - _params['$skipToken'] = _SERIALIZER.query("skip_token", skip_token, 'str') + _params["$skipToken"] = _SERIALIZER.query("skip_token", skip_token, "str") if count is not None: - _params['$count'] = _SERIALIZER.query("count", count, 'bool') + _params["$count"] = _SERIALIZER.query("count", count, "bool") if filter is not None: - _params['$filter'] = _SERIALIZER.query("filter", filter, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$filter"] = _SERIALIZER.query("filter", filter, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_update_request( - resource_group_name: str, - managed_instance_name: str, - database_name: str, - subscription_id: str, - *, - json: Optional[_models.SensitivityLabelUpdateList] = None, - content: Any = None, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/currentSensitivityLabels") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/currentSensitivityLabels", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) def build_list_recommended_by_database_request( @@ -356,39 +331,39 @@ def build_list_recommended_by_database_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/recommendedSensitivityLabels") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/recommendedSensitivityLabels", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if skip_token is not None: - _params['$skipToken'] = _SERIALIZER.query("skip_token", skip_token, 'str') + _params["$skipToken"] = _SERIALIZER.query("skip_token", skip_token, "str") if include_disabled_recommendations is not None: - _params['includeDisabledRecommendations'] = _SERIALIZER.query("include_disabled_recommendations", include_disabled_recommendations, 'bool') + _params["includeDisabledRecommendations"] = _SERIALIZER.query( + "include_disabled_recommendations", include_disabled_recommendations, "bool" + ) if filter is not None: - _params['$filter'] = _SERIALIZER.query("filter", filter, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$filter"] = _SERIALIZER.query("filter", filter, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedDatabaseSensitivityLabelsOperations: """ @@ -409,7 +384,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -425,40 +399,35 @@ def get( """Gets the sensitivity label of a given column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :param sensitivity_label_source: The source of the sensitivity label. + :param sensitivity_label_source: The source of the sensitivity label. Known values are: + "current" and "recommended". Required. :type sensitivity_label_source: str or ~azure.mgmt.sql.models.SensitivityLabelSource - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SensitivityLabel, or the result of cls(response) + :return: SensitivityLabel or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SensitivityLabel - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SensitivityLabel] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SensitivityLabel] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -469,7 +438,7 @@ def get( sensitivity_label_source=sensitivity_label_source, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -477,27 +446,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SensitivityLabel', pipeline_response) + deserialized = self._deserialize("SensitivityLabel", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore - - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, @@ -507,50 +474,141 @@ def create_or_update( table_name: str, column_name: str, parameters: _models.SensitivityLabel, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.SensitivityLabel: """Creates or updates the sensitivity label of a given column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :param parameters: The column sensitivity label resource. + :param parameters: The column sensitivity label resource. Required. :type parameters: ~azure.mgmt.sql.models.SensitivityLabel + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str :keyword sensitivity_label_source: The source of the sensitivity label. Default value is "current". Note that overriding this default value may result in unsupported behavior. :paramtype sensitivity_label_source: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SensitivityLabel, or the result of cls(response) + :return: SensitivityLabel or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SensitivityLabel - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + schema_name: str, + table_name: str, + column_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.SensitivityLabel: + """Creates or updates the sensitivity label of a given column. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param schema_name: The name of the schema. Required. + :type schema_name: str + :param table_name: The name of the table. Required. + :type table_name: str + :param column_name: The name of the column. Required. + :type column_name: str + :param parameters: The column sensitivity label resource. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword sensitivity_label_source: The source of the sensitivity label. Default value is + "current". Note that overriding this default value may result in unsupported behavior. + :paramtype sensitivity_label_source: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SensitivityLabel or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.SensitivityLabel + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + schema_name: str, + table_name: str, + column_name: str, + parameters: Union[_models.SensitivityLabel, IO], + **kwargs: Any + ) -> _models.SensitivityLabel: + """Creates or updates the sensitivity label of a given column. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param schema_name: The name of the schema. Required. + :type schema_name: str + :param table_name: The name of the table. Required. + :type table_name: str + :param column_name: The name of the column. Required. + :type column_name: str + :param parameters: The column sensitivity label resource. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.SensitivityLabel or IO + :keyword sensitivity_label_source: The source of the sensitivity label. Default value is + "current". Note that overriding this default value may result in unsupported behavior. + :paramtype sensitivity_label_source: str + :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 + :return: SensitivityLabel or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.SensitivityLabel + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "current") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.SensitivityLabel] + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "current") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.SensitivityLabel] - _json = self._serialize.body(parameters, 'SensitivityLabel') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SensitivityLabel") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -564,7 +622,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -572,10 +631,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -583,18 +641,17 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('SensitivityLabel', pipeline_response) + deserialized = self._deserialize("SensitivityLabel", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('SensitivityLabel', pipeline_response) + deserialized = self._deserialize("SensitivityLabel", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -610,42 +667,36 @@ def delete( # pylint: disable=inconsistent-return-statements """Deletes the sensitivity label of a given column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str :keyword sensitivity_label_source: The source of the sensitivity label. Default value is "current". Note that overriding this default value may result in unsupported behavior. :paramtype sensitivity_label_source: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "current") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "current") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -656,7 +707,7 @@ def delete( # pylint: disable=inconsistent-return-statements subscription_id=self._config.subscription_id, sensitivity_label_source=sensitivity_label_source, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -664,10 +715,9 @@ def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -677,8 +727,7 @@ def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore @distributed_trace def disable_recommendation( # pylint: disable=inconsistent-return-statements @@ -694,42 +743,36 @@ def disable_recommendation( # pylint: disable=inconsistent-return-statements """Disables sensitivity recommendations on a given column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :keyword sensitivity_label_source: Default value is "recommended". Note that overriding this + :keyword sensitivity_label_source: Default value is "recommended". Note that overriding this default value may result in unsupported behavior. :paramtype sensitivity_label_source: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "recommended") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "recommended") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_disable_recommendation_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -740,7 +783,7 @@ def disable_recommendation( # pylint: disable=inconsistent-return-statements subscription_id=self._config.subscription_id, sensitivity_label_source=sensitivity_label_source, api_version=api_version, - template_url=self.disable_recommendation.metadata['url'], + template_url=self.disable_recommendation.metadata["url"], headers=_headers, params=_params, ) @@ -748,10 +791,9 @@ def disable_recommendation( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -761,8 +803,7 @@ def disable_recommendation( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - disable_recommendation.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/disable"} # type: ignore - + disable_recommendation.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/disable"} # type: ignore @distributed_trace def enable_recommendation( # pylint: disable=inconsistent-return-statements @@ -779,42 +820,36 @@ def enable_recommendation( # pylint: disable=inconsistent-return-statements on all columns). :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :keyword sensitivity_label_source: Default value is "recommended". Note that overriding this + :keyword sensitivity_label_source: Default value is "recommended". Note that overriding this default value may result in unsupported behavior. :paramtype sensitivity_label_source: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "recommended") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "recommended") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_enable_recommendation_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -825,7 +860,7 @@ def enable_recommendation( # pylint: disable=inconsistent-return-statements subscription_id=self._config.subscription_id, sensitivity_label_source=sensitivity_label_source, api_version=api_version, - template_url=self.enable_recommendation.metadata['url'], + template_url=self.enable_recommendation.metadata["url"], headers=_headers, params=_params, ) @@ -833,10 +868,9 @@ def enable_recommendation( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -846,8 +880,7 @@ def enable_recommendation( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - enable_recommendation.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/enable"} # type: ignore - + enable_recommendation.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/enable"} # type: ignore @distributed_trace def list_current_by_database( @@ -859,55 +892,50 @@ def list_current_by_database( count: Optional[bool] = None, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable[_models.SensitivityLabelListResult]: + ) -> Iterable["_models.SensitivityLabel"]: """Gets the sensitivity labels of a given database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param skip_token: Default value is None. + :param skip_token: Default value is None. :type skip_token: str - :param count: Default value is None. + :param count: Default value is None. :type count: bool :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SensitivityLabelListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SensitivityLabelListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SensitivityLabel or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SensitivityLabel] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SensitivityLabelListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SensitivityLabelListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_current_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, skip_token=skip_token, count=count, filter=filter, - template_url=self.list_current_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_current_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -915,20 +943,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_current_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - skip_token=skip_token, - count=count, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -944,10 +959,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -957,53 +970,117 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_current_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/currentSensitivityLabels"} # type: ignore + list_current_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/currentSensitivityLabels"} # type: ignore - @distributed_trace + @overload def update( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, managed_instance_name: str, database_name: str, parameters: _models.SensitivityLabelUpdateList, + *, + content_type: str = "application/json", **kwargs: Any ) -> None: """Update sensitivity labels of a given database using an operations batch. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.SensitivityLabelUpdateList - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> None: + """Update sensitivity labels of a given database using an operations batch. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Required. + :type parameters: IO + :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: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @distributed_trace + def update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.SensitivityLabelUpdateList, IO], + **kwargs: Any + ) -> None: + """Update sensitivity labels of a given database using an operations batch. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.SensitivityLabelUpdateList 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 + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'SensitivityLabelUpdateList') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SensitivityLabelUpdateList") request = build_update_request( resource_group_name=resource_group_name, @@ -1013,7 +1090,8 @@ def update( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -1021,10 +1099,9 @@ def update( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -1034,8 +1111,7 @@ def update( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/currentSensitivityLabels"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/currentSensitivityLabels"} # type: ignore @distributed_trace def list_recommended_by_database( @@ -1047,17 +1123,17 @@ def list_recommended_by_database( include_disabled_recommendations: Optional[bool] = None, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable[_models.SensitivityLabelListResult]: + ) -> Iterable["_models.SensitivityLabel"]: """Gets the sensitivity labels of a given database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param skip_token: Default value is None. + :param skip_token: Default value is None. :type skip_token: str :param include_disabled_recommendations: Specifies whether to include disabled recommendations or not. Default value is None. @@ -1065,38 +1141,33 @@ def list_recommended_by_database( :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SensitivityLabelListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SensitivityLabelListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SensitivityLabel or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SensitivityLabel] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SensitivityLabelListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SensitivityLabelListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_recommended_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, skip_token=skip_token, include_disabled_recommendations=include_disabled_recommendations, filter=filter, - template_url=self.list_recommended_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_recommended_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -1104,20 +1175,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_recommended_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - skip_token=skip_token, - include_disabled_recommendations=include_disabled_recommendations, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1133,10 +1191,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1146,8 +1202,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_recommended_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/recommendedSensitivityLabels"} # type: ignore + list_recommended_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/recommendedSensitivityLabels"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_tables_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_tables_operations.py index e3cfd6441c300..66055df0a1ea5 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_tables_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_tables_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_schema_request( resource_group_name: str, managed_instance_name: str, @@ -40,36 +47,33 @@ def build_list_by_schema_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if filter is not None: - _params['$filter'] = _SERIALIZER.query("filter", filter, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$filter"] = _SERIALIZER.query("filter", filter, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -84,35 +88,33 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "tableName": _SERIALIZER.url("table_name", table_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "tableName": _SERIALIZER.url("table_name", table_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedDatabaseTablesOperations: """ @@ -133,7 +135,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_schema( self, @@ -143,52 +144,47 @@ def list_by_schema( schema_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable[_models.DatabaseTableListResult]: + ) -> Iterable["_models.DatabaseTable"]: """List managed database tables. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseTableListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseTableListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseTable or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseTable] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseTableListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseTableListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_schema_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, schema_name=schema_name, subscription_id=self._config.subscription_id, - api_version=api_version, filter=filter, - template_url=self.list_by_schema.metadata['url'], + api_version=api_version, + template_url=self.list_by_schema.metadata["url"], headers=_headers, params=_params, ) @@ -196,19 +192,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_schema_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - schema_name=schema_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -224,10 +208,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -237,11 +219,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_schema.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables"} # type: ignore + list_by_schema.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables"} # type: ignore @distributed_trace def get( @@ -256,36 +236,30 @@ def get( """Get managed database table. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseTable, or the result of cls(response) + :return: DatabaseTable or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseTable - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseTable] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseTable] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -294,7 +268,7 @@ def get( table_name=table_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -302,22 +276,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseTable', pipeline_response) + deserialized = self._deserialize("DatabaseTable", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_transparent_data_encryption_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_transparent_data_encryption_operations.py index a57ecee6ed5b1..0837993908d35 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_transparent_data_encryption_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_transparent_data_encryption_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, managed_instance_name: str, @@ -38,34 +45,31 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption/{tdeName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption/{tdeName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "tdeName": _SERIALIZER.url("tde_name", tde_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "tdeName": _SERIALIZER.url("tde_name", tde_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( @@ -74,86 +78,72 @@ def build_create_or_update_request( database_name: str, tde_name: Union[str, "_models.TransparentDataEncryptionName"], subscription_id: str, - *, - json: Optional[_models.ManagedTransparentDataEncryption] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption/{tdeName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption/{tdeName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "tdeName": _SERIALIZER.url("tde_name", tde_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "tdeName": _SERIALIZER.url("tde_name", tde_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_database_request( - resource_group_name: str, - managed_instance_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedDatabaseTransparentDataEncryptionOperations: """ @@ -174,7 +164,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -187,35 +176,29 @@ def get( """Gets a managed database's transparent data encryption. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the managed database for which the transparent data - encryption is defined. + encryption is defined. Required. :type database_name: str - :param tde_name: The name of the transparent data encryption configuration. + :param tde_name: The name of the transparent data encryption configuration. "current" Required. :type tde_name: str or ~azure.mgmt.sql.models.TransparentDataEncryptionName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedTransparentDataEncryption, or the result of cls(response) + :return: ManagedTransparentDataEncryption or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedTransparentDataEncryption - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedTransparentDataEncryption] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedTransparentDataEncryption] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -223,7 +206,7 @@ def get( tde_name=tde_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -231,27 +214,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedTransparentDataEncryption', pipeline_response) + deserialized = self._deserialize("ManagedTransparentDataEncryption", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption/{tdeName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption/{tdeName}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, @@ -259,43 +240,118 @@ def create_or_update( database_name: str, tde_name: Union[str, "_models.TransparentDataEncryptionName"], parameters: _models.ManagedTransparentDataEncryption, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.ManagedTransparentDataEncryption: """Updates a database's transparent data encryption configuration. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the managed database for which the security alert policy is - defined. + defined. Required. :type database_name: str - :param tde_name: The name of the transparent data encryption configuration. + :param tde_name: The name of the transparent data encryption configuration. "current" Required. :type tde_name: str or ~azure.mgmt.sql.models.TransparentDataEncryptionName - :param parameters: The database transparent data encryption. + :param parameters: The database transparent data encryption. Required. :type parameters: ~azure.mgmt.sql.models.ManagedTransparentDataEncryption - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: ManagedTransparentDataEncryption or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedTransparentDataEncryption + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + tde_name: Union[str, "_models.TransparentDataEncryptionName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.ManagedTransparentDataEncryption: + """Updates a database's transparent data encryption configuration. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the managed database for which the security alert policy is + defined. Required. + :type database_name: str + :param tde_name: The name of the transparent data encryption configuration. "current" Required. + :type tde_name: str or ~azure.mgmt.sql.models.TransparentDataEncryptionName + :param parameters: The database transparent data encryption. Required. + :type parameters: IO + :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: ManagedTransparentDataEncryption or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedTransparentDataEncryption + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + tde_name: Union[str, "_models.TransparentDataEncryptionName"], + parameters: Union[_models.ManagedTransparentDataEncryption, IO], + **kwargs: Any + ) -> _models.ManagedTransparentDataEncryption: + """Updates a database's transparent data encryption configuration. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the managed database for which the security alert policy is + defined. Required. + :type database_name: str + :param tde_name: The name of the transparent data encryption configuration. "current" Required. + :type tde_name: str or ~azure.mgmt.sql.models.TransparentDataEncryptionName + :param parameters: The database transparent data encryption. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedTransparentDataEncryption 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 - :return: ManagedTransparentDataEncryption, or the result of cls(response) + :return: ManagedTransparentDataEncryption or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedTransparentDataEncryption - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedTransparentDataEncryption] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedTransparentDataEncryption] - _json = self._serialize.body(parameters, 'ManagedTransparentDataEncryption') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedTransparentDataEncryption") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -306,7 +362,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -314,10 +371,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -325,67 +381,57 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('ManagedTransparentDataEncryption', pipeline_response) + deserialized = self._deserialize("ManagedTransparentDataEncryption", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedTransparentDataEncryption', pipeline_response) + deserialized = self._deserialize("ManagedTransparentDataEncryption", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption/{tdeName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption/{tdeName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.ManagedTransparentDataEncryptionListResult]: + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedTransparentDataEncryption"]: """Gets a list of managed database's transparent data encryptions. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the managed database for which the transparent data - encryption is defined. + encryption is defined. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedTransparentDataEncryptionListResult or the - result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedTransparentDataEncryptionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedTransparentDataEncryption or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedTransparentDataEncryption] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedTransparentDataEncryptionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedTransparentDataEncryptionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -393,17 +439,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -419,10 +455,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -432,8 +466,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/transparentDataEncryption"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_vulnerability_assessment_rule_baselines_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_vulnerability_assessment_rule_baselines_operations.py index 3cc1b91a6e64f..18e024fb8cf95 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_vulnerability_assessment_rule_baselines_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_vulnerability_assessment_rule_baselines_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar, Union - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse from azure.core.rest import HttpRequest @@ -19,13 +23,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, managed_instance_name: str, @@ -39,36 +46,35 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "ruleId": _SERIALIZER.url("rule_id", rule_id, 'str'), - "baselineName": _SERIALIZER.url("baseline_name", baseline_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "ruleId": _SERIALIZER.url("rule_id", rule_id, "str"), + "baselineName": _SERIALIZER.url("baseline_name", baseline_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( @@ -79,49 +85,43 @@ def build_create_or_update_request( rule_id: str, baseline_name: Union[str, "_models.VulnerabilityAssessmentPolicyBaselineName"], subscription_id: str, - *, - json: Optional[_models.DatabaseVulnerabilityAssessmentRuleBaseline] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "ruleId": _SERIALIZER.url("rule_id", rule_id, 'str'), - "baselineName": _SERIALIZER.url("baseline_name", baseline_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "ruleId": _SERIALIZER.url("rule_id", rule_id, "str"), + "baselineName": _SERIALIZER.url("baseline_name", baseline_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_delete_request( @@ -136,30 +136,31 @@ def build_delete_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "ruleId": _SERIALIZER.url("rule_id", rule_id, 'str'), - "baselineName": _SERIALIZER.url("baseline_name", baseline_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "ruleId": _SERIALIZER.url("rule_id", rule_id, "str"), + "baselineName": _SERIALIZER.url("baseline_name", baseline_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) class ManagedDatabaseVulnerabilityAssessmentRuleBaselinesOperations: """ @@ -180,7 +181,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -195,40 +195,36 @@ def get( """Gets a database's vulnerability assessment rule baseline. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the database for which the vulnerability assessment rule - baseline is defined. + baseline is defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param rule_id: The vulnerability assessment rule ID. + :param rule_id: The vulnerability assessment rule ID. Required. :type rule_id: str :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a - baseline on a database level rule and master for server level rule). + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseVulnerabilityAssessmentRuleBaseline, or the result of cls(response) + :return: DatabaseVulnerabilityAssessmentRuleBaseline or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentRuleBaseline] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentRuleBaseline] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -238,7 +234,7 @@ def get( baseline_name=baseline_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -246,27 +242,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseVulnerabilityAssessmentRuleBaseline', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessmentRuleBaseline", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, @@ -276,48 +270,143 @@ def create_or_update( rule_id: str, baseline_name: Union[str, "_models.VulnerabilityAssessmentPolicyBaselineName"], parameters: _models.DatabaseVulnerabilityAssessmentRuleBaseline, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DatabaseVulnerabilityAssessmentRuleBaseline: """Creates or updates a database's vulnerability assessment rule baseline. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the database for which the vulnerability assessment rule - baseline is defined. + baseline is defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param rule_id: The vulnerability assessment rule ID. + :param rule_id: The vulnerability assessment rule ID. Required. :type rule_id: str :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a - baseline on a database level rule and master for server level rule). + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName - :param parameters: The requested rule baseline resource. + :param parameters: The requested rule baseline resource. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: DatabaseVulnerabilityAssessmentRuleBaseline or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + rule_id: str, + baseline_name: Union[str, "_models.VulnerabilityAssessmentPolicyBaselineName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DatabaseVulnerabilityAssessmentRuleBaseline: + """Creates or updates a database's vulnerability assessment rule baseline. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database for which the vulnerability assessment rule + baseline is defined. Required. + :type database_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param rule_id: The vulnerability assessment rule ID. Required. + :type rule_id: str + :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. + :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName + :param parameters: The requested rule baseline resource. Required. + :type parameters: IO + :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: DatabaseVulnerabilityAssessmentRuleBaseline or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + rule_id: str, + baseline_name: Union[str, "_models.VulnerabilityAssessmentPolicyBaselineName"], + parameters: Union[_models.DatabaseVulnerabilityAssessmentRuleBaseline, IO], + **kwargs: Any + ) -> _models.DatabaseVulnerabilityAssessmentRuleBaseline: + """Creates or updates a database's vulnerability assessment rule baseline. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database for which the vulnerability assessment rule + baseline is defined. Required. + :type database_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param rule_id: The vulnerability assessment rule ID. Required. + :type rule_id: str + :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. + :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName + :param parameters: The requested rule baseline resource. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline 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 - :return: DatabaseVulnerabilityAssessmentRuleBaseline, or the result of cls(response) + :return: DatabaseVulnerabilityAssessmentRuleBaseline or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentRuleBaseline - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentRuleBaseline] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentRuleBaseline] - _json = self._serialize.body(parameters, 'DatabaseVulnerabilityAssessmentRuleBaseline') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseVulnerabilityAssessmentRuleBaseline") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -330,7 +419,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -338,25 +428,23 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseVulnerabilityAssessmentRuleBaseline', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessmentRuleBaseline", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -372,40 +460,36 @@ def delete( # pylint: disable=inconsistent-return-statements """Removes the database's vulnerability assessment rule baseline. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the database for which the vulnerability assessment rule - baseline is defined. + baseline is defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param rule_id: The vulnerability assessment rule ID. + :param rule_id: The vulnerability assessment rule ID. Required. :type rule_id: str :param baseline_name: The name of the vulnerability assessment rule baseline (default implies a - baseline on a database level rule and master for server level rule). + baseline on a database level rule and master for server level rule). Known values are: "master" + and "default". Required. :type baseline_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentPolicyBaselineName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -415,7 +499,7 @@ def delete( # pylint: disable=inconsistent-return-statements baseline_name=baseline_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -423,10 +507,9 @@ def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -436,5 +519,4 @@ def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/rules/{ruleId}/baselines/{baselineName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_vulnerability_assessment_scans_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_vulnerability_assessment_scans_operations.py index 62534f62e3b28..9e9749b7188a5 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_vulnerability_assessment_scans_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_vulnerability_assessment_scans_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,14 +26,17 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False -def build_initiate_scan_request_initial( + +def build_initiate_scan_request( resource_group_name: str, managed_instance_name: str, database_name: str, @@ -40,29 +47,29 @@ def build_initiate_scan_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "scanId": _SERIALIZER.url("scan_id", scan_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "scanId": _SERIALIZER.url("scan_id", scan_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) def build_export_request( @@ -77,35 +84,34 @@ def build_export_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/export") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/export", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "scanId": _SERIALIZER.url("scan_id", scan_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "scanId": _SERIALIZER.url("scan_id", scan_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_database_request( @@ -119,34 +125,33 @@ def build_list_by_database_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -161,35 +166,35 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "scanId": _SERIALIZER.url("scan_id", scan_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "scanId": _SERIALIZER.url("scan_id", scan_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedDatabaseVulnerabilityAssessmentScansOperations: """ @@ -210,7 +215,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - def _initiate_scan_initial( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, @@ -220,19 +224,16 @@ def _initiate_scan_initial( # pylint: disable=inconsistent-return-statements scan_id: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_initiate_scan_request_initial( + request = build_initiate_scan_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, @@ -240,7 +241,7 @@ def _initiate_scan_initial( # pylint: disable=inconsistent-return-statements scan_id=scan_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._initiate_scan_initial.metadata['url'], + template_url=self._initiate_scan_initial.metadata["url"], headers=_headers, params=_params, ) @@ -248,10 +249,9 @@ def _initiate_scan_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -261,11 +261,10 @@ def _initiate_scan_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _initiate_scan_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan"} # type: ignore - + _initiate_scan_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan"} # type: ignore @distributed_trace - def begin_initiate_scan( # pylint: disable=inconsistent-return-statements + def begin_initiate_scan( self, resource_group_name: str, managed_instance_name: str, @@ -277,19 +276,17 @@ def begin_initiate_scan( # pylint: disable=inconsistent-return-statements """Executes a Vulnerability Assessment database scan. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param scan_id: The vulnerability assessment scan Id of the scan to retrieve. + :param scan_id: The vulnerability assessment scan Id of the scan to retrieve. Required. :type scan_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -300,19 +297,16 @@ def begin_initiate_scan( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._initiate_scan_initial( # type: ignore resource_group_name=resource_group_name, @@ -321,37 +315,33 @@ def begin_initiate_scan( # pylint: disable=inconsistent-return-statements vulnerability_assessment_name=vulnerability_assessment_name, scan_id=scan_id, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_initiate_scan.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan"} # type: ignore + begin_initiate_scan.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan"} # type: ignore @distributed_trace def export( @@ -366,36 +356,31 @@ def export( """Convert an existing scan result to a human readable format. If already exists nothing happens. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the scanned database. + :param database_name: The name of the scanned database. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param scan_id: The vulnerability assessment scan Id. + :param scan_id: The vulnerability assessment scan Id. Required. :type scan_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseVulnerabilityAssessmentScansExport, or the result of cls(response) + :return: DatabaseVulnerabilityAssessmentScansExport or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentScansExport - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentScansExport] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentScansExport] - request = build_export_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -404,7 +389,7 @@ def export( scan_id=scan_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.export.metadata['url'], + template_url=self.export.metadata["url"], headers=_headers, params=_params, ) @@ -412,10 +397,9 @@ def export( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -423,18 +407,17 @@ def export( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('DatabaseVulnerabilityAssessmentScansExport', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessmentScansExport", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DatabaseVulnerabilityAssessmentScansExport', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessmentScansExport", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - export.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/export"} # type: ignore - + export.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/export"} # type: ignore @distributed_trace def list_by_database( @@ -444,41 +427,37 @@ def list_by_database( database_name: str, vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], **kwargs: Any - ) -> Iterable[_models.VulnerabilityAssessmentScanRecordListResult]: + ) -> Iterable["_models.VulnerabilityAssessmentScanRecord"]: """Lists the vulnerability assessment scans of a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VulnerabilityAssessmentScanRecordListResult or the - result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.VulnerabilityAssessmentScanRecordListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either VulnerabilityAssessmentScanRecord or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.VulnerabilityAssessmentScanRecord] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VulnerabilityAssessmentScanRecordListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VulnerabilityAssessmentScanRecordListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -486,7 +465,7 @@ def prepare_request(next_link=None): vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -494,18 +473,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - vulnerability_assessment_name=vulnerability_assessment_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -521,10 +489,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -534,11 +500,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans"} # type: ignore @distributed_trace def get( @@ -553,36 +517,31 @@ def get( """Gets a vulnerability assessment scan record of a database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param scan_id: The vulnerability assessment scan Id of the scan to retrieve. + :param scan_id: The vulnerability assessment scan Id of the scan to retrieve. Required. :type scan_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VulnerabilityAssessmentScanRecord, or the result of cls(response) + :return: VulnerabilityAssessmentScanRecord or the result of cls(response) :rtype: ~azure.mgmt.sql.models.VulnerabilityAssessmentScanRecord - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VulnerabilityAssessmentScanRecord] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VulnerabilityAssessmentScanRecord] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -591,7 +550,7 @@ def get( scan_id=scan_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -599,22 +558,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('VulnerabilityAssessmentScanRecord', pipeline_response) + deserialized = self._deserialize("VulnerabilityAssessmentScanRecord", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_vulnerability_assessments_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_vulnerability_assessments_operations.py index 3af0760812c15..5fca080dc52e7 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_vulnerability_assessments_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_database_vulnerability_assessments_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, managed_instance_name: str, @@ -38,34 +45,33 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( @@ -74,47 +80,41 @@ def build_create_or_update_request( database_name: str, vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], subscription_id: str, - *, - json: Optional[_models.DatabaseVulnerabilityAssessment] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_delete_request( @@ -127,67 +127,61 @@ def build_delete_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_database_request( - resource_group_name: str, - managed_instance_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedDatabaseVulnerabilityAssessmentsOperations: """ @@ -208,7 +202,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -221,35 +214,30 @@ def get( """Gets the database's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the database for which the vulnerability assessment is - defined. + defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DatabaseVulnerabilityAssessment, or the result of cls(response) + :return: DatabaseVulnerabilityAssessment or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessment] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessment] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -257,7 +245,7 @@ def get( vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -265,27 +253,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('DatabaseVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, @@ -293,43 +279,120 @@ def create_or_update( database_name: str, vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], parameters: _models.DatabaseVulnerabilityAssessment, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.DatabaseVulnerabilityAssessment: """Creates or updates the database's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the database for which the vulnerability assessment is - defined. + defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param parameters: The requested resource. + :param parameters: The requested resource. Required. :type parameters: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: DatabaseVulnerabilityAssessment or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.DatabaseVulnerabilityAssessment: + """Creates or updates the database's vulnerability assessment. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database for which the vulnerability assessment is + defined. Required. + :type database_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param parameters: The requested resource. Required. + :type parameters: IO + :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: DatabaseVulnerabilityAssessment or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + parameters: Union[_models.DatabaseVulnerabilityAssessment, IO], + **kwargs: Any + ) -> _models.DatabaseVulnerabilityAssessment: + """Creates or updates the database's vulnerability assessment. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database for which the vulnerability assessment is + defined. Required. + :type database_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param parameters: The requested resource. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment 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 - :return: DatabaseVulnerabilityAssessment, or the result of cls(response) + :return: DatabaseVulnerabilityAssessment or the result of cls(response) :rtype: ~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessment] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessment] - _json = self._serialize.body(parameters, 'DatabaseVulnerabilityAssessment') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "DatabaseVulnerabilityAssessment") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -340,7 +403,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -348,10 +412,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -359,18 +422,17 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('DatabaseVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessment", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('DatabaseVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("DatabaseVulnerabilityAssessment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -384,35 +446,30 @@ def delete( # pylint: disable=inconsistent-return-statements """Removes the database's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the database for which the vulnerability assessment is - defined. + defined. Required. :type database_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -420,7 +477,7 @@ def delete( # pylint: disable=inconsistent-return-statements vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -428,10 +485,9 @@ def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -441,57 +497,47 @@ def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.DatabaseVulnerabilityAssessmentListResult]: + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.DatabaseVulnerabilityAssessment"]: """Lists the vulnerability assessments of a managed database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param database_name: The name of the database for which the vulnerability assessment is - defined. + defined. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DatabaseVulnerabilityAssessmentListResult or the - result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseVulnerabilityAssessmentListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either DatabaseVulnerabilityAssessment or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.DatabaseVulnerabilityAssessment] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.DatabaseVulnerabilityAssessmentListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -499,17 +545,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -525,10 +561,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -538,8 +572,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_databases_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_databases_operations.py index d1166aabbe539..ec7731fa51603 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_databases_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_databases_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,294 +26,333 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_instance_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - managed_instance_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, database_name: str, subscription_id: str, **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", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}", + ) # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, managed_instance_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - resource_group_name: str, - managed_instance_name: str, - database_name: str, - subscription_id: str, - *, - json: Optional[_models.ManagedDatabase] = None, - content: Any = None, - **kwargs: Any + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_delete_request( + resource_group_name: str, managed_instance_name: str, database_name: str, subscription_id: str, **kwargs: Any +) -> HttpRequest: + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}", + ) # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) + + +def build_update_request( + resource_group_name: str, managed_instance_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) - - -def build_delete_request_initial( - resource_group_name: str, - managed_instance_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_cancel_move_request( + resource_group_name: str, managed_instance_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/cancelMove", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') - - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) - - -def build_update_request_initial( - resource_group_name: str, - managed_instance_name: str, - database_name: str, - subscription_id: str, - *, - json: Optional[_models.ManagedDatabaseUpdate] = None, - content: Any = None, - **kwargs: Any + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_complete_move_request( + resource_group_name: str, managed_instance_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/completeMove", + ) # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_complete_restore_request( + resource_group_name: str, managed_instance_name: str, database_name: str, subscription_id: str, **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", "2022-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/completeRestore", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) - - -def build_complete_restore_request_initial( - resource_group_name: str, - managed_instance_name: str, - database_name: str, - subscription_id: str, - *, - json: Optional[_models.CompleteDatabaseRestoreDefinition] = None, - content: Any = None, - **kwargs: Any + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_start_move_request( + resource_group_name: str, managed_instance_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/completeRestore") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/startMove", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) def build_list_inaccessible_by_instance_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/inaccessibleManagedDatabases") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/inaccessibleManagedDatabases", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedDatabasesOperations: """ @@ -330,49 +373,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> Iterable[_models.ManagedDatabaseListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedDatabase"]: """Gets a list of managed databases. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedDatabaseListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedDatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedDatabase or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -380,16 +414,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -405,10 +430,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -418,56 +441,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any ) -> _models.ManagedDatabase: """Gets a managed database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedDatabase, or the result of cls(response) + :return: ManagedDatabase or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedDatabase - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabase] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabase] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -475,49 +486,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedDatabase', pipeline_response) + deserialized = self._deserialize("ManagedDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, database_name: str, - parameters: _models.ManagedDatabase, + parameters: Union[_models.ManagedDatabase, IO], **kwargs: Any ) -> Optional[_models.ManagedDatabase]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedDatabase]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedDatabase]] - _json = self._serialize.body(parameters, 'ManagedDatabase') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedDatabase") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, @@ -525,7 +538,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -533,10 +547,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -545,42 +558,120 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedDatabase', pipeline_response) + deserialized = self._deserialize("ManagedDatabase", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedDatabase', pipeline_response) + deserialized = self._deserialize("ManagedDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, database_name: str, parameters: _models.ManagedDatabase, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ManagedDatabase]: """Creates a new database or updates an existing database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The requested database resource state. + :param parameters: The requested database resource state. Required. :type parameters: ~azure.mgmt.sql.models.ManagedDatabase - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ManagedDatabase or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedDatabase]: + """Creates a new database or updates an existing database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested database resource state. Required. + :type parameters: IO + :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 ManagedDatabase or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.ManagedDatabase, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedDatabase]: + """Creates a new database or updates an existing database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested database resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabase 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 @@ -592,20 +683,17 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ManagedDatabase or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedDatabase] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabase] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabase] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -614,66 +702,55 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedDatabase', pipeline_response) + deserialized = self._deserialize("ManagedDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -681,10 +758,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -694,29 +770,21 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes a managed database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -727,80 +795,77 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore def _update_initial( self, resource_group_name: str, managed_instance_name: str, database_name: str, - parameters: _models.ManagedDatabaseUpdate, + parameters: Union[_models.ManagedDatabaseUpdate, IO], **kwargs: Any ) -> Optional[_models.ManagedDatabase]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedDatabase]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedDatabase]] - _json = self._serialize.body(parameters, 'ManagedDatabaseUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedDatabaseUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, @@ -808,7 +873,8 @@ def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -816,10 +882,9 @@ def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -828,39 +893,117 @@ def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedDatabase', pipeline_response) + deserialized = self._deserialize("ManagedDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore - + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore - @distributed_trace + @overload def begin_update( self, resource_group_name: str, managed_instance_name: str, database_name: str, parameters: _models.ManagedDatabaseUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ManagedDatabase]: """Updates an existing database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The requested database resource state. + :param parameters: The requested database resource state. Required. :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseUpdate - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ManagedDatabase or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedDatabase]: + """Updates an existing database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested database resource state. Required. + :type parameters: IO + :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 ManagedDatabase or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.ManagedDatabaseUpdate, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedDatabase]: + """Updates an existing database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The requested database resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseUpdate 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 @@ -872,20 +1015,17 @@ def begin_update( :return: An instance of LROPoller that returns either ManagedDatabase or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedDatabase] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabase] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabase] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -894,63 +1034,63 @@ def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedDatabase', pipeline_response) + deserialized = self._deserialize("ManagedDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}"} # type: ignore - def _complete_restore_initial( # pylint: disable=inconsistent-return-statements + def _cancel_move_initial( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, managed_instance_name: str, database_name: str, - parameters: _models.CompleteDatabaseRestoreDefinition, + parameters: Union[_models.ManagedDatabaseMoveDefinition, IO], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'CompleteDatabaseRestoreDefinition') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedDatabaseMoveDefinition") - request = build_complete_restore_request_initial( + request = build_cancel_move_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, @@ -958,7 +1098,8 @@ def _complete_restore_initial( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self._complete_restore_initial.metadata['url'], + content=_content, + template_url=self._cancel_move_initial.metadata["url"], headers=_headers, params=_params, ) @@ -966,10 +1107,9 @@ def _complete_restore_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -979,32 +1119,33 @@ def _complete_restore_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _complete_restore_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/completeRestore"} # type: ignore + _cancel_move_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/cancelMove"} # type: ignore - - @distributed_trace - def begin_complete_restore( # pylint: disable=inconsistent-return-statements + @overload + def begin_cancel_move( self, resource_group_name: str, managed_instance_name: str, database_name: str, - parameters: _models.CompleteDatabaseRestoreDefinition, + parameters: _models.ManagedDatabaseMoveDefinition, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[None]: - """Completes the restore operation on a managed database. + """Cancels a managed database move operation. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The definition for completing the restore of this managed database. - :type parameters: ~azure.mgmt.sql.models.CompleteDatabaseRestoreDefinition - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :param parameters: Parameters of the cancel managed database move operation. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseMoveDefinition + :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 @@ -1015,102 +1156,806 @@ def begin_complete_restore( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] - if cont_token is None: - raw_result = self._complete_restore_initial( # type: ignore - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - parameters=parameters, - api_version=api_version, - content_type=content_type, - cls=lambda x,y,z: x, - headers=_headers, - params=_params, - **kwargs - ) - kwargs.pop('error_map', None) - - def get_long_running_output(pipeline_response): - if cls: + @overload + def begin_cancel_move( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[None]: + """Cancels a managed database move operation. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters of the cancel managed database move operation. Required. + :type parameters: IO + :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: + """ + + @distributed_trace + def begin_cancel_move( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.ManagedDatabaseMoveDefinition, IO], + **kwargs: Any + ) -> LROPoller[None]: + """Cancels a managed database move operation. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters of the cancel managed database move operation. Is either a model + type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseMoveDefinition 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. + :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: + """ + _headers = case_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: str + 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] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + if cont_token is None: + raw_result = self._cancel_move_initial( # type: ignore + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements + if cls: return cls(pipeline_response, None, {}) + if polling is True: + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling + if cont_token: + return LROPoller.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_cancel_move.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/cancelMove"} # type: ignore + + def _complete_move_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.ManagedDatabaseMoveDefinition, IO], + **kwargs: Any + ) -> None: + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_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: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedDatabaseMoveDefinition") + + request = build_complete_move_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self._complete_move_initial.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _complete_move_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/completeMove"} # type: ignore + + @overload + def begin_complete_move( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: _models.ManagedDatabaseMoveDefinition, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[None]: + """Completes a managed database move operation. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters of the complete managed database move operation. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseMoveDefinition + :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: + """ + + @overload + def begin_complete_move( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[None]: + """Completes a managed database move operation. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters of the complete managed database move operation. Required. + :type parameters: IO + :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: + """ + + @distributed_trace + def begin_complete_move( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.ManagedDatabaseMoveDefinition, IO], + **kwargs: Any + ) -> LROPoller[None]: + """Completes a managed database move operation. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters of the complete managed database move operation. Is either a + model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseMoveDefinition 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. + :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: + """ + _headers = case_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: str + 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] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + if cont_token is None: + raw_result = self._complete_move_initial( # type: ignore + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements + if cls: + return cls(pipeline_response, None, {}) if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling + if cont_token: + return LROPoller.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_complete_move.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/completeMove"} # type: ignore + + def _complete_restore_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.CompleteDatabaseRestoreDefinition, IO], + **kwargs: Any + ) -> None: + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_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: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "CompleteDatabaseRestoreDefinition") + + request = build_complete_restore_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self._complete_restore_initial.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _complete_restore_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/completeRestore"} # type: ignore + + @overload + def begin_complete_restore( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: _models.CompleteDatabaseRestoreDefinition, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[None]: + """Completes the restore operation on a managed database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The definition for completing the restore of this managed database. + Required. + :type parameters: ~azure.mgmt.sql.models.CompleteDatabaseRestoreDefinition + :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: + """ + + @overload + def begin_complete_restore( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[None]: + """Completes the restore operation on a managed database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The definition for completing the restore of this managed database. + Required. + :type parameters: IO + :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: + """ + + @distributed_trace + def begin_complete_restore( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.CompleteDatabaseRestoreDefinition, IO], + **kwargs: Any + ) -> LROPoller[None]: + """Completes the restore operation on a managed database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The definition for completing the restore of this managed database. Is + either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.CompleteDatabaseRestoreDefinition 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. + :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: + """ + _headers = case_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: str + 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] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + if cont_token is None: + raw_result = self._complete_restore_initial( # type: ignore + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements + if cls: + return cls(pipeline_response, None, {}) + + if polling is True: + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_complete_restore.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/completeRestore"} # type: ignore + begin_complete_restore.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/completeRestore"} # type: ignore + + def _start_move_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: Union[_models.ManagedDatabaseStartMoveDefinition, IO], + **kwargs: Any + ) -> None: + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_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: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedDatabaseStartMoveDefinition") + + request = build_start_move_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self._start_move_initial.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _start_move_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/startMove"} # type: ignore + + @overload + def begin_start_move( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: _models.ManagedDatabaseStartMoveDefinition, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[None]: + """Starts a managed database move operation. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters of the start managed database move operation. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseStartMoveDefinition + :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: + """ + + @overload + def begin_start_move( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[None]: + """Starts a managed database move operation. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters of the start managed database move operation. Required. + :type parameters: IO + :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: + """ @distributed_trace - def list_inaccessible_by_instance( + def begin_start_move( self, resource_group_name: str, managed_instance_name: str, + database_name: str, + parameters: Union[_models.ManagedDatabaseStartMoveDefinition, IO], **kwargs: Any - ) -> Iterable[_models.ManagedDatabaseListResult]: + ) -> LROPoller[None]: + """Starts a managed database move operation. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Parameters of the start managed database move operation. Is either a model + type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedDatabaseStartMoveDefinition 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. + :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: + """ + _headers = case_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: str + 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] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + if cont_token is None: + raw_result = self._start_move_initial( # type: ignore + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + database_name=database_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements + if cls: + return cls(pipeline_response, None, {}) + + if polling is True: + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling + if cont_token: + return LROPoller.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_move.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/startMove"} # type: ignore + + @distributed_trace + def list_inaccessible_by_instance( + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedDatabase"]: """Gets a list of inaccessible managed databases in a managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedDatabaseListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedDatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedDatabase or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedDatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedDatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_inaccessible_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_inaccessible_by_instance.metadata['url'], + template_url=self.list_inaccessible_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -1118,16 +1963,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_inaccessible_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1143,10 +1979,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1156,8 +1990,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_inaccessible_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/inaccessibleManagedDatabases"} # type: ignore + list_inaccessible_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/inaccessibleManagedDatabases"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_administrators_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_administrators_operations.py index 5a3bc6867a7fe..aa2a3f4848fda 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_administrators_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_administrators_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,48 +26,45 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_instance_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -76,83 +77,72 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "administratorName": _SERIALIZER.url("administrator_name", administrator_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "administratorName": _SERIALIZER.url("administrator_name", administrator_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, managed_instance_name: str, administrator_name: Union[str, "_models.AdministratorName"], subscription_id: str, - *, - json: Optional[_models.ManagedInstanceAdministrator] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "administratorName": _SERIALIZER.url("administrator_name", administrator_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "administratorName": _SERIALIZER.url("administrator_name", administrator_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_request_initial( +def build_delete_request( resource_group_name: str, managed_instance_name: str, administrator_name: Union[str, "_models.AdministratorName"], @@ -161,27 +151,26 @@ def build_delete_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "administratorName": _SERIALIZER.url("administrator_name", administrator_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "administratorName": _SERIALIZER.url("administrator_name", administrator_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) class ManagedInstanceAdministratorsOperations: """ @@ -202,50 +191,41 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> Iterable[_models.ManagedInstanceAdministratorListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedInstanceAdministrator"]: """Gets a list of managed instance administrators. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceAdministratorListResult or the - result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceAdministratorListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedInstanceAdministrator or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceAdministrator] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceAdministratorListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAdministratorListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -253,16 +233,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -278,10 +249,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -291,11 +260,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators"} # type: ignore @distributed_trace def get( @@ -308,39 +275,33 @@ def get( """Gets a managed instance administrator. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param administrator_name: + :param administrator_name: "ActiveDirectory" Required. :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceAdministrator, or the result of cls(response) + :return: ManagedInstanceAdministrator or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceAdministrator - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceAdministrator] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAdministrator] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, administrator_name=administrator_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -348,49 +309,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceAdministrator', pipeline_response) + deserialized = self._deserialize("ManagedInstanceAdministrator", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, administrator_name: Union[str, "_models.AdministratorName"], - parameters: _models.ManagedInstanceAdministrator, + parameters: Union[_models.ManagedInstanceAdministrator, IO], **kwargs: Any ) -> Optional[_models.ManagedInstanceAdministrator]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedInstanceAdministrator]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstanceAdministrator]] - _json = self._serialize.body(parameters, 'ManagedInstanceAdministrator') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceAdministrator") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, administrator_name=administrator_name, @@ -398,7 +361,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -406,10 +370,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -418,42 +381,43 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedInstanceAdministrator', pipeline_response) + deserialized = self._deserialize("ManagedInstanceAdministrator", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedInstanceAdministrator', pipeline_response) + deserialized = self._deserialize("ManagedInstanceAdministrator", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, administrator_name: Union[str, "_models.AdministratorName"], parameters: _models.ManagedInstanceAdministrator, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ManagedInstanceAdministrator]: """Creates or updates a managed instance administrator. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param administrator_name: + :param administrator_name: "ActiveDirectory" Required. :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName - :param parameters: The requested administrator parameters. + :param parameters: The requested administrator parameters. Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstanceAdministrator - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -465,20 +429,94 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ManagedInstanceAdministrator or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceAdministrator] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + administrator_name: Union[str, "_models.AdministratorName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedInstanceAdministrator]: + """Creates or updates a managed instance administrator. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param administrator_name: "ActiveDirectory" Required. + :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName + :param parameters: The requested administrator parameters. Required. + :type parameters: IO + :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 ManagedInstanceAdministrator or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceAdministrator] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + administrator_name: Union[str, "_models.AdministratorName"], + parameters: Union[_models.ManagedInstanceAdministrator, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedInstanceAdministrator]: + """Creates or updates a managed instance administrator. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param administrator_name: "ActiveDirectory" Required. + :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName + :param parameters: The requested administrator parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceAdministrator 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. + :return: An instance of LROPoller that returns either ManagedInstanceAdministrator or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceAdministrator] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceAdministrator] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAdministrator] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -487,39 +525,35 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedInstanceAdministrator', pipeline_response) + deserialized = self._deserialize("ManagedInstanceAdministrator", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements self, @@ -528,25 +562,22 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements administrator_name: Union[str, "_models.AdministratorName"], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, administrator_name=administrator_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -554,10 +585,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -567,11 +597,10 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements + def begin_delete( self, resource_group_name: str, managed_instance_name: str, @@ -581,15 +610,12 @@ def begin_delete( # pylint: disable=inconsistent-return-statements """Deletes a managed instance administrator. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param administrator_name: + :param administrator_name: "ActiveDirectory" Required. :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -600,53 +626,46 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, administrator_name=administrator_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/administrators/{administratorName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_advanced_threat_protection_settings_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_advanced_threat_protection_settings_operations.py new file mode 100644 index 0000000000000..374f4953373a5 --- /dev/null +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_advanced_threat_protection_settings_operations.py @@ -0,0 +1,539 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import 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 azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from .._serialization import Serializer +from .._vendor import _convert_request, _format_url_section + +T = TypeVar("T") +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False + + +def build_list_by_instance_request( + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/advancedThreatProtectionSettings", + ) # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_get_request( + resource_group_name: str, + managed_instance_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + subscription_id: str, + **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", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}", + ) # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "advancedThreatProtectionName": _SERIALIZER.url( + "advanced_threat_protection_name", advanced_threat_protection_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, + managed_instance_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + subscription_id: str, + **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", "2022-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}", + ) # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "advancedThreatProtectionName": _SERIALIZER.url( + "advanced_threat_protection_name", advanced_threat_protection_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +class ManagedInstanceAdvancedThreatProtectionSettingsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.mgmt.sql.SqlManagementClient`'s + :attr:`managed_instance_advanced_threat_protection_settings` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs): + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace + def list_by_instance( + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedInstanceAdvancedThreatProtection"]: + """Get the managed instance's Advanced Threat Protection settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ManagedInstanceAdvancedThreatProtection or the + result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _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: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAdvancedThreatProtectionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_instance_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_instance.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + else: + request = HttpRequest("GET", next_link) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("ManagedInstanceAdvancedThreatProtectionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/advancedThreatProtectionSettings"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name: str, + managed_instance_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + **kwargs: Any + ) -> _models.ManagedInstanceAdvancedThreatProtection: + """Get a managed instance's Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ManagedInstanceAdvancedThreatProtection or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedInstanceAdvancedThreatProtection + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + _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: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAdvancedThreatProtection] + + request = build_get_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + advanced_threat_protection_name=advanced_threat_protection_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 + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("ManagedInstanceAdvancedThreatProtection", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore + + def _create_or_update_initial( + self, + resource_group_name: str, + managed_instance_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: Union[_models.ManagedInstanceAdvancedThreatProtection, IO], + **kwargs: Any + ) -> Optional[_models.ManagedInstanceAdvancedThreatProtection]: + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_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: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstanceAdvancedThreatProtection]] + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceAdvancedThreatProtection") + + request = build_create_or_update_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + advanced_threat_protection_name=advanced_threat_protection_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + 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 + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize("ManagedInstanceAdvancedThreatProtection", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: _models.ManagedInstanceAdvancedThreatProtection, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedInstanceAdvancedThreatProtection]: + """Creates or updates Advanced Threat Protection settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The managed instance Advanced Threat Protection state. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceAdvancedThreatProtection + :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 ManagedInstanceAdvancedThreatProtection + or the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedInstanceAdvancedThreatProtection]: + """Creates or updates Advanced Threat Protection settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The managed instance Advanced Threat Protection state. Required. + :type parameters: IO + :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 ManagedInstanceAdvancedThreatProtection + or the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: Union[_models.ManagedInstanceAdvancedThreatProtection, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedInstanceAdvancedThreatProtection]: + """Creates or updates Advanced Threat Protection settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The managed instance Advanced Threat Protection state. Is either a model + type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceAdvancedThreatProtection 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. + :return: An instance of LROPoller that returns either ManagedInstanceAdvancedThreatProtection + or the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = case_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: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAdvancedThreatProtection] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + if cont_token is None: + raw_result = self._create_or_update_initial( # type: ignore + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + advanced_threat_protection_name=advanced_threat_protection_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): + deserialized = self._deserialize("ManagedInstanceAdvancedThreatProtection", pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + if polling is True: + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling + if cont_token: + return LROPoller.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.Sql/managedInstances/{managedInstanceName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_azure_ad_only_authentications_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_azure_ad_only_authentications_operations.py index 7015c0bb533f1..0f6bf83f905ad 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_azure_ad_only_authentications_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_azure_ad_only_authentications_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, managed_instance_name: str, @@ -39,83 +46,72 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "authenticationName": _SERIALIZER.url("authentication_name", authentication_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "authenticationName": _SERIALIZER.url("authentication_name", authentication_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, managed_instance_name: str, authentication_name: Union[str, "_models.AuthenticationName"], subscription_id: str, - *, - json: Optional[_models.ManagedInstanceAzureADOnlyAuthentication] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "authenticationName": _SERIALIZER.url("authentication_name", authentication_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "authenticationName": _SERIALIZER.url("authentication_name", authentication_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_request_initial( +def build_delete_request( resource_group_name: str, managed_instance_name: str, authentication_name: Union[str, "_models.AuthenticationName"], @@ -124,64 +120,57 @@ def build_delete_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "authenticationName": _SERIALIZER.url("authentication_name", authentication_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "authenticationName": _SERIALIZER.url("authentication_name", authentication_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_instance_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedInstanceAzureADOnlyAuthenticationsOperations: """ @@ -202,7 +191,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -214,39 +202,34 @@ def get( """Gets a specific Azure Active Directory only authentication property. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceAzureADOnlyAuthentication, or the result of cls(response) + :return: ManagedInstanceAzureADOnlyAuthentication or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceAzureADOnlyAuthentication - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceAzureADOnlyAuthentication] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAzureADOnlyAuthentication] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, authentication_name=authentication_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -254,49 +237,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceAzureADOnlyAuthentication', pipeline_response) + deserialized = self._deserialize("ManagedInstanceAzureADOnlyAuthentication", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, authentication_name: Union[str, "_models.AuthenticationName"], - parameters: _models.ManagedInstanceAzureADOnlyAuthentication, + parameters: Union[_models.ManagedInstanceAzureADOnlyAuthentication, IO], **kwargs: Any ) -> Optional[_models.ManagedInstanceAzureADOnlyAuthentication]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedInstanceAzureADOnlyAuthentication]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstanceAzureADOnlyAuthentication]] - _json = self._serialize.body(parameters, 'ManagedInstanceAzureADOnlyAuthentication') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceAzureADOnlyAuthentication") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, authentication_name=authentication_name, @@ -304,7 +289,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -312,10 +298,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -324,44 +309,130 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedInstanceAzureADOnlyAuthentication', pipeline_response) + deserialized = self._deserialize("ManagedInstanceAzureADOnlyAuthentication", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedInstanceAzureADOnlyAuthentication', pipeline_response) + deserialized = self._deserialize("ManagedInstanceAzureADOnlyAuthentication", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, authentication_name: Union[str, "_models.AuthenticationName"], parameters: _models.ManagedInstanceAzureADOnlyAuthentication, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ManagedInstanceAzureADOnlyAuthentication]: """Sets Server Active Directory only authentication property or updates an existing server Active Directory only authentication property. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName :param parameters: The required parameters for creating or updating an Active Directory only - authentication property. + authentication property. Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstanceAzureADOnlyAuthentication - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ManagedInstanceAzureADOnlyAuthentication + or the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceAzureADOnlyAuthentication] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + authentication_name: Union[str, "_models.AuthenticationName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedInstanceAzureADOnlyAuthentication]: + """Sets Server Active Directory only authentication property or updates an existing server Active + Directory only authentication property. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. + :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName + :param parameters: The required parameters for creating or updating an Active Directory only + authentication property. Required. + :type parameters: IO + :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 ManagedInstanceAzureADOnlyAuthentication + or the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceAzureADOnlyAuthentication] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + authentication_name: Union[str, "_models.AuthenticationName"], + parameters: Union[_models.ManagedInstanceAzureADOnlyAuthentication, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedInstanceAzureADOnlyAuthentication]: + """Sets Server Active Directory only authentication property or updates an existing server Active + Directory only authentication property. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. + :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName + :param parameters: The required parameters for creating or updating an Active Directory only + authentication property. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceAzureADOnlyAuthentication 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 @@ -374,20 +445,17 @@ def begin_create_or_update( or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceAzureADOnlyAuthentication] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceAzureADOnlyAuthentication] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAzureADOnlyAuthentication] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -396,39 +464,35 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedInstanceAzureADOnlyAuthentication', pipeline_response) + deserialized = self._deserialize("ManagedInstanceAzureADOnlyAuthentication", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements self, @@ -437,25 +501,22 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements authentication_name: Union[str, "_models.AuthenticationName"], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, authentication_name=authentication_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -463,10 +524,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -476,11 +536,10 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements + def begin_delete( self, resource_group_name: str, managed_instance_name: str, @@ -490,15 +549,13 @@ def begin_delete( # pylint: disable=inconsistent-return-statements """Deletes an existing server Active Directory only authentication property. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -509,100 +566,86 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, authentication_name=authentication_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> Iterable[_models.ManagedInstanceAzureADOnlyAuthListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedInstanceAzureADOnlyAuthentication"]: """Gets a list of server Azure Active Directory only authentications. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceAzureADOnlyAuthListResult or the + :return: An iterator like instance of either ManagedInstanceAzureADOnlyAuthentication or the result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceAzureADOnlyAuthListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceAzureADOnlyAuthentication] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceAzureADOnlyAuthListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceAzureADOnlyAuthListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -610,16 +653,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -635,10 +669,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -648,8 +680,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/azureADOnlyAuthentications"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_dtcs_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_dtcs_operations.py new file mode 100644 index 0000000000000..62025115a1d63 --- /dev/null +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_dtcs_operations.py @@ -0,0 +1,520 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import 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 azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from .._serialization import Serializer +from .._vendor import _convert_request, _format_url_section + +T = TypeVar("T") +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False + + +def build_list_by_managed_instance_request( + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dtc", + ) # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_get_request( + resource_group_name: str, + managed_instance_name: str, + dtc_name: Union[str, "_models.DtcName"], + subscription_id: str, + **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", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dtc/{dtcName}", + ) # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "dtcName": _SERIALIZER.url("dtc_name", dtc_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, + managed_instance_name: str, + dtc_name: Union[str, "_models.DtcName"], + subscription_id: str, + **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", "2022-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dtc/{dtcName}", + ) # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "dtcName": _SERIALIZER.url("dtc_name", dtc_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +class ManagedInstanceDtcsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.mgmt.sql.SqlManagementClient`'s + :attr:`managed_instance_dtcs` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs): + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace + def list_by_managed_instance( + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedInstanceDtc"]: + """Gets a list of managed instance DTC settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ManagedInstanceDtc or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceDtc] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _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: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceDtcListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_managed_instance_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_managed_instance.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + + else: + request = HttpRequest("GET", next_link) + request = _convert_request(request) + request.url = self._client.format_url(request.url) # type: ignore + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("ManagedInstanceDtcListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list_by_managed_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dtc"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name: str, + managed_instance_name: str, + dtc_name: Union[str, "_models.DtcName"], + **kwargs: Any + ) -> _models.ManagedInstanceDtc: + """Gets managed instance DTC settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param dtc_name: The name of the managed instance DTC. "current" Required. + :type dtc_name: str or ~azure.mgmt.sql.models.DtcName + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ManagedInstanceDtc or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedInstanceDtc + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + _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: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceDtc] + + request = build_get_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + dtc_name=dtc_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 + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("ManagedInstanceDtc", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dtc/{dtcName}"} # type: ignore + + def _create_or_update_initial( + self, + resource_group_name: str, + managed_instance_name: str, + dtc_name: Union[str, "_models.DtcName"], + parameters: Union[_models.ManagedInstanceDtc, IO], + **kwargs: Any + ) -> _models.ManagedInstanceDtc: + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_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: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceDtc] + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceDtc") + + request = build_create_or_update_request( + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + dtc_name=dtc_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + 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 + + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("ManagedInstanceDtc", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dtc/{dtcName}"} # type: ignore + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + dtc_name: Union[str, "_models.DtcName"], + parameters: _models.ManagedInstanceDtc, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedInstanceDtc]: + """Updates managed instance DTC settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param dtc_name: The name of the managed instance DTC. "current" Required. + :type dtc_name: str or ~azure.mgmt.sql.models.DtcName + :param parameters: Managed instance DTC settings. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceDtc + :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 ManagedInstanceDtc or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceDtc] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + dtc_name: Union[str, "_models.DtcName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedInstanceDtc]: + """Updates managed instance DTC settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param dtc_name: The name of the managed instance DTC. "current" Required. + :type dtc_name: str or ~azure.mgmt.sql.models.DtcName + :param parameters: Managed instance DTC settings. Required. + :type parameters: IO + :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 ManagedInstanceDtc or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceDtc] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + dtc_name: Union[str, "_models.DtcName"], + parameters: Union[_models.ManagedInstanceDtc, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedInstanceDtc]: + """Updates managed instance DTC settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param dtc_name: The name of the managed instance DTC. "current" Required. + :type dtc_name: str or ~azure.mgmt.sql.models.DtcName + :param parameters: Managed instance DTC settings. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceDtc 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. + :return: An instance of LROPoller that returns either ManagedInstanceDtc or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceDtc] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = case_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: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceDtc] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + if cont_token is None: + raw_result = self._create_or_update_initial( # type: ignore + resource_group_name=resource_group_name, + managed_instance_name=managed_instance_name, + dtc_name=dtc_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): + deserialized = self._deserialize("ManagedInstanceDtc", pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + if polling is True: + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling + if cont_token: + return LROPoller.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.Sql/managedInstances/{managedInstanceName}/dtc/{dtcName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_encryption_protectors_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_encryption_protectors_operations.py index 182829b2a7572..62b5cd92279c5 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_encryption_protectors_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_encryption_protectors_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,14 +26,17 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False -def build_revalidate_request_initial( + +def build_revalidate_request( resource_group_name: str, managed_instance_name: str, encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], @@ -38,64 +45,56 @@ def build_revalidate_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}/revalidate") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}/revalidate", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "encryptionProtectorName": _SERIALIZER.url("encryption_protector_name", encryption_protector_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "encryptionProtectorName": _SERIALIZER.url("encryption_protector_name", encryption_protector_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) def build_list_by_instance_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -108,80 +107,70 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "encryptionProtectorName": _SERIALIZER.url("encryption_protector_name", encryption_protector_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "encryptionProtectorName": _SERIALIZER.url("encryption_protector_name", encryption_protector_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, managed_instance_name: str, encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], subscription_id: str, - *, - json: Optional[_models.ManagedInstanceEncryptionProtector] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "encryptionProtectorName": _SERIALIZER.url("encryption_protector_name", encryption_protector_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "encryptionProtectorName": _SERIALIZER.url("encryption_protector_name", encryption_protector_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + class ManagedInstanceEncryptionProtectorsOperations: """ @@ -202,7 +191,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - def _revalidate_initial( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, @@ -210,25 +198,22 @@ def _revalidate_initial( # pylint: disable=inconsistent-return-statements encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_revalidate_request_initial( + request = build_revalidate_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, encryption_protector_name=encryption_protector_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._revalidate_initial.metadata['url'], + template_url=self._revalidate_initial.metadata["url"], headers=_headers, params=_params, ) @@ -236,10 +221,9 @@ def _revalidate_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -249,11 +233,10 @@ def _revalidate_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _revalidate_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}/revalidate"} # type: ignore - + _revalidate_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}/revalidate"} # type: ignore @distributed_trace - def begin_revalidate( # pylint: disable=inconsistent-return-statements + def begin_revalidate( self, resource_group_name: str, managed_instance_name: str, @@ -263,15 +246,13 @@ def begin_revalidate( # pylint: disable=inconsistent-return-statements """Revalidates an existing encryption protector. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param encryption_protector_name: The name of the encryption protector to be updated. + :param encryption_protector_name: The name of the encryption protector to be updated. "current" + Required. :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -282,100 +263,85 @@ def begin_revalidate( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._revalidate_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, encryption_protector_name=encryption_protector_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_revalidate.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}/revalidate"} # type: ignore + begin_revalidate.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}/revalidate"} # type: ignore @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> Iterable[_models.ManagedInstanceEncryptionProtectorListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedInstanceEncryptionProtector"]: """Gets a list of managed instance encryption protectors. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceEncryptionProtectorListResult or - the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceEncryptionProtectorListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedInstanceEncryptionProtector or the result + of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceEncryptionProtector] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceEncryptionProtectorListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceEncryptionProtectorListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -383,16 +349,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -408,10 +365,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -421,11 +376,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector"} # type: ignore @distributed_trace def get( @@ -438,39 +391,34 @@ def get( """Gets a managed instance encryption protector. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param encryption_protector_name: The name of the encryption protector to be retrieved. + "current" Required. :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceEncryptionProtector, or the result of cls(response) + :return: ManagedInstanceEncryptionProtector or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceEncryptionProtector - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceEncryptionProtector] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceEncryptionProtector] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, encryption_protector_name=encryption_protector_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -478,49 +426,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceEncryptionProtector', pipeline_response) + deserialized = self._deserialize("ManagedInstanceEncryptionProtector", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], - parameters: _models.ManagedInstanceEncryptionProtector, + parameters: Union[_models.ManagedInstanceEncryptionProtector, IO], **kwargs: Any ) -> Optional[_models.ManagedInstanceEncryptionProtector]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedInstanceEncryptionProtector]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstanceEncryptionProtector]] - _json = self._serialize.body(parameters, 'ManagedInstanceEncryptionProtector') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceEncryptionProtector") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, encryption_protector_name=encryption_protector_name, @@ -528,7 +478,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -536,10 +487,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -548,39 +498,82 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedInstanceEncryptionProtector', pipeline_response) + deserialized = self._deserialize("ManagedInstanceEncryptionProtector", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], parameters: _models.ManagedInstanceEncryptionProtector, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ManagedInstanceEncryptionProtector]: """Updates an existing encryption protector. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param encryption_protector_name: The name of the encryption protector to be updated. + :param encryption_protector_name: The name of the encryption protector to be updated. "current" + Required. :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName - :param parameters: The requested encryption protector resource state. + :param parameters: The requested encryption protector resource state. Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstanceEncryptionProtector - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ManagedInstanceEncryptionProtector or the + result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceEncryptionProtector] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedInstanceEncryptionProtector]: + """Updates an existing encryption protector. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param encryption_protector_name: The name of the encryption protector to be updated. "current" + Required. + :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName + :param parameters: The requested encryption protector resource state. Required. + :type parameters: IO + :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 @@ -593,20 +586,57 @@ def begin_create_or_update( result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceEncryptionProtector] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + encryption_protector_name: Union[str, "_models.EncryptionProtectorName"], + parameters: Union[_models.ManagedInstanceEncryptionProtector, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedInstanceEncryptionProtector]: + """Updates an existing encryption protector. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param encryption_protector_name: The name of the encryption protector to be updated. "current" + Required. + :type encryption_protector_name: str or ~azure.mgmt.sql.models.EncryptionProtectorName + :param parameters: The requested encryption protector resource state. Is either a model type or + a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceEncryptionProtector 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. + :return: An instance of LROPoller that returns either ManagedInstanceEncryptionProtector or the + result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceEncryptionProtector] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceEncryptionProtector] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceEncryptionProtector] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -615,36 +645,32 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedInstanceEncryptionProtector', pipeline_response) + deserialized = self._deserialize("ManagedInstanceEncryptionProtector", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/encryptionProtector/{encryptionProtectorName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_keys_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_keys_operations.py index 5fcc23140f137..f1e476bb1e646 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_keys_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_keys_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_instance_request( resource_group_name: str, managed_instance_name: str, @@ -40,152 +47,125 @@ def build_list_by_instance_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if filter is not None: - _params['$filter'] = _SERIALIZER.query("filter", filter, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$filter"] = _SERIALIZER.query("filter", filter, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - managed_instance_name: str, - key_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, key_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "keyName": _SERIALIZER.url("key_name", key_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "keyName": _SERIALIZER.url("key_name", key_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( - resource_group_name: str, - managed_instance_name: str, - key_name: str, - subscription_id: str, - *, - json: Optional[_models.ManagedInstanceKey] = None, - content: Any = None, - **kwargs: Any +def build_create_or_update_request( + resource_group_name: str, managed_instance_name: str, key_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "keyName": _SERIALIZER.url("key_name", key_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "keyName": _SERIALIZER.url("key_name", key_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_request_initial( - resource_group_name: str, - managed_instance_name: str, - key_name: str, - subscription_id: str, - **kwargs: Any +def build_delete_request( + resource_group_name: str, managed_instance_name: str, key_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "keyName": _SERIALIZER.url("key_name", key_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "keyName": _SERIALIZER.url("key_name", key_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) class ManagedInstanceKeysOperations: """ @@ -206,54 +186,44 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - filter: Optional[str] = None, - **kwargs: Any - ) -> Iterable[_models.ManagedInstanceKeyListResult]: + self, resource_group_name: str, managed_instance_name: str, filter: Optional[str] = None, **kwargs: Any + ) -> Iterable["_models.ManagedInstanceKey"]: """Gets a list of managed instance keys. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceKeyListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceKeyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedInstanceKey or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceKey] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceKeyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceKeyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, - api_version=api_version, filter=filter, - template_url=self.list_by_instance.metadata['url'], + api_version=api_version, + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -261,17 +231,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -287,10 +247,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -300,56 +258,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - managed_instance_name: str, - key_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, key_name: str, **kwargs: Any ) -> _models.ManagedInstanceKey: """Gets a managed instance key. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param key_name: The name of the managed instance key to be retrieved. + :param key_name: The name of the managed instance key to be retrieved. Required. :type key_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceKey, or the result of cls(response) + :return: ManagedInstanceKey or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceKey - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceKey] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceKey] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, key_name=key_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -357,49 +303,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceKey', pipeline_response) + deserialized = self._deserialize("ManagedInstanceKey", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, key_name: str, - parameters: _models.ManagedInstanceKey, + parameters: Union[_models.ManagedInstanceKey, IO], **kwargs: Any ) -> Optional[_models.ManagedInstanceKey]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedInstanceKey]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstanceKey]] - _json = self._serialize.body(parameters, 'ManagedInstanceKey') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceKey") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, key_name=key_name, @@ -407,7 +355,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -415,10 +364,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -427,42 +375,123 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedInstanceKey', pipeline_response) + deserialized = self._deserialize("ManagedInstanceKey", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedInstanceKey', pipeline_response) + deserialized = self._deserialize("ManagedInstanceKey", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, key_name: str, parameters: _models.ManagedInstanceKey, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ManagedInstanceKey]: """Creates or updates a managed instance key. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param key_name: The name of the managed instance key to be operated on (updated or created). + Required. :type key_name: str - :param parameters: The requested managed instance key resource state. + :param parameters: The requested managed instance key resource state. Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstanceKey - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ManagedInstanceKey or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceKey] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + key_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedInstanceKey]: + """Creates or updates a managed instance key. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param key_name: The name of the managed instance key to be operated on (updated or created). + Required. + :type key_name: str + :param parameters: The requested managed instance key resource state. Required. + :type parameters: IO + :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 ManagedInstanceKey or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceKey] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + key_name: str, + parameters: Union[_models.ManagedInstanceKey, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedInstanceKey]: + """Creates or updates a managed instance key. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param key_name: The name of the managed instance key to be operated on (updated or created). + Required. + :type key_name: str + :param parameters: The requested managed instance key resource state. Is either a model type or + a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceKey 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 @@ -474,20 +503,17 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ManagedInstanceKey or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceKey] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceKey] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceKey] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -496,66 +522,55 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedInstanceKey', pipeline_response) + deserialized = self._deserialize("ManagedInstanceKey", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - key_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, key_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, key_name=key_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -563,10 +578,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -576,29 +590,21 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - key_name: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, managed_instance_name: str, key_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes the managed instance key with the given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param key_name: The name of the managed instance key to be deleted. + :param key_name: The name of the managed instance key to be deleted. Required. :type key_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -609,53 +615,46 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, key_name=key_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/keys/{keyName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_long_term_retention_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_long_term_retention_policies_operations.py index ba19a0a11a64c..02f9e2d8d55d6 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_long_term_retention_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_long_term_retention_policies_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, managed_instance_name: str, @@ -40,122 +47,105 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "policyName": _SERIALIZER.url("policy_name", policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "policyName": _SERIALIZER.url("policy_name", policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, managed_instance_name: str, database_name: str, policy_name: Union[str, "_models.ManagedInstanceLongTermRetentionPolicyName"], subscription_id: str, - *, - json: Optional[_models.ManagedInstanceLongTermRetentionPolicy] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "policyName": _SERIALIZER.url("policy_name", policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "policyName": _SERIALIZER.url("policy_name", policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_database_request( - resource_group_name: str, - managed_instance_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedInstanceLongTermRetentionPoliciesOperations: """ @@ -176,7 +166,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -189,34 +178,28 @@ def get( """Gets a managed database's long term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be Default. + :param policy_name: The policy name. Should always be Default. "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicyName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceLongTermRetentionPolicy, or the result of cls(response) + :return: ManagedInstanceLongTermRetentionPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionPolicy] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -224,7 +207,7 @@ def get( policy_name=policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -232,25 +215,23 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceLongTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedInstanceLongTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore def _create_or_update_initial( self, @@ -258,24 +239,28 @@ def _create_or_update_initial( managed_instance_name: str, database_name: str, policy_name: Union[str, "_models.ManagedInstanceLongTermRetentionPolicyName"], - parameters: _models.ManagedInstanceLongTermRetentionPolicy, + parameters: Union[_models.ManagedInstanceLongTermRetentionPolicy, IO], **kwargs: Any ) -> Optional[_models.ManagedInstanceLongTermRetentionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedInstanceLongTermRetentionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstanceLongTermRetentionPolicy]] - _json = self._serialize.body(parameters, 'ManagedInstanceLongTermRetentionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceLongTermRetentionPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, @@ -284,7 +269,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -292,10 +278,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -304,17 +289,16 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedInstanceLongTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedInstanceLongTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, @@ -322,24 +306,26 @@ def begin_create_or_update( database_name: str, policy_name: Union[str, "_models.ManagedInstanceLongTermRetentionPolicyName"], parameters: _models.ManagedInstanceLongTermRetentionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ManagedInstanceLongTermRetentionPolicy]: """Sets a managed database's long term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param policy_name: The policy name. Should always be Default. + :param policy_name: The policy name. Should always be Default. "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicyName - :param parameters: The long term retention policy info. + :param parameters: The long term retention policy info. Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -352,20 +338,102 @@ def begin_create_or_update( the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + policy_name: Union[str, "_models.ManagedInstanceLongTermRetentionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedInstanceLongTermRetentionPolicy]: + """Sets a managed database's long term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be Default. "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicyName + :param parameters: The long term retention policy info. Required. + :type parameters: IO + :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 ManagedInstanceLongTermRetentionPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + database_name: str, + policy_name: Union[str, "_models.ManagedInstanceLongTermRetentionPolicyName"], + parameters: Union[_models.ManagedInstanceLongTermRetentionPolicy, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedInstanceLongTermRetentionPolicy]: + """Sets a managed database's long term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param policy_name: The policy name. Should always be Default. "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicyName + :param parameters: The long term retention policy info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicy 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. + :return: An instance of LROPoller that returns either ManagedInstanceLongTermRetentionPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -375,87 +443,75 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedInstanceLongTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedInstanceLongTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies/{policyName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - managed_instance_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.ManagedInstanceLongTermRetentionPolicyListResult]: + self, resource_group_name: str, managed_instance_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedInstanceLongTermRetentionPolicy"]: """Gets a database's long term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceLongTermRetentionPolicyListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstanceLongTermRetentionPolicy or the + result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceLongTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceLongTermRetentionPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceLongTermRetentionPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -463,17 +519,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -489,10 +535,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -502,8 +546,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/backupLongTermRetentionPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_operations_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_operations_operations.py index cb8ad0084d99a..9ff4894f0daad 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_operations_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_operations_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,119 +24,104 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_managed_instance_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - managed_instance_name: str, - operation_id: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, operation_id: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations/{operationId}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations/{operationId}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "operationId": _SERIALIZER.url("operation_id", operation_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "operationId": _SERIALIZER.url("operation_id", operation_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_cancel_request( - resource_group_name: str, - managed_instance_name: str, - operation_id: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, operation_id: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations/{operationId}/cancel") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations/{operationId}/cancel", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "operationId": _SERIALIZER.url("operation_id", operation_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "operationId": _SERIALIZER.url("operation_id", operation_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) class ManagedInstanceOperationsOperations: """ @@ -153,49 +142,41 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_managed_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> Iterable[_models.ManagedInstanceOperationListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedInstanceOperation"]: """Gets a list of operations performed on the managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceOperationListResult or the result - of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceOperationListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedInstanceOperation or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceOperation] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceOperationListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceOperationListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_managed_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_managed_instance.metadata['url'], + template_url=self.list_by_managed_instance.metadata["url"], headers=_headers, params=_params, ) @@ -203,16 +184,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_managed_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -228,10 +200,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -241,56 +211,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_managed_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations"} # type: ignore + list_by_managed_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - managed_instance_name: str, - operation_id: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, operation_id: str, **kwargs: Any ) -> _models.ManagedInstanceOperation: """Gets a management operation on a managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param operation_id: + :param operation_id: Required. :type operation_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceOperation, or the result of cls(response) + :return: ManagedInstanceOperation or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceOperation - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceOperation] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceOperation] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, operation_id=operation_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -298,70 +256,58 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceOperation', pipeline_response) + deserialized = self._deserialize("ManagedInstanceOperation", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations/{operationId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations/{operationId}"} # type: ignore @distributed_trace def cancel( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - operation_id: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, operation_id: str, **kwargs: Any ) -> None: """Cancels the asynchronous operation on the managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param operation_id: + :param operation_id: Required. :type operation_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_cancel_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, operation_id=operation_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.cancel.metadata['url'], + template_url=self.cancel.metadata["url"], headers=_headers, params=_params, ) @@ -369,10 +315,9 @@ def cancel( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -382,5 +327,4 @@ def cancel( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - cancel.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations/{operationId}/cancel"} # type: ignore - + cancel.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/operations/{operationId}/cancel"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_private_endpoint_connections_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_private_endpoint_connections_operations.py index f77967628ddba..57e966c2b1281 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_private_endpoint_connections_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_private_endpoint_connections_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, managed_instance_name: str, @@ -39,83 +46,76 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "privateEndpointConnectionName": _SERIALIZER.url("private_endpoint_connection_name", private_endpoint_connection_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "privateEndpointConnectionName": _SERIALIZER.url( + "private_endpoint_connection_name", private_endpoint_connection_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, managed_instance_name: str, private_endpoint_connection_name: str, subscription_id: str, - *, - json: Optional[_models.ManagedInstancePrivateEndpointConnection] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "privateEndpointConnectionName": _SERIALIZER.url("private_endpoint_connection_name", private_endpoint_connection_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "privateEndpointConnectionName": _SERIALIZER.url( + "private_endpoint_connection_name", private_endpoint_connection_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_request_initial( +def build_delete_request( resource_group_name: str, managed_instance_name: str, private_endpoint_connection_name: str, @@ -124,64 +124,59 @@ def build_delete_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "privateEndpointConnectionName": _SERIALIZER.url("private_endpoint_connection_name", private_endpoint_connection_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "privateEndpointConnectionName": _SERIALIZER.url( + "private_endpoint_connection_name", private_endpoint_connection_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_managed_instance_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedInstancePrivateEndpointConnectionsOperations: """ @@ -202,51 +197,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( - self, - resource_group_name: str, - managed_instance_name: str, - private_endpoint_connection_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, private_endpoint_connection_name: str, **kwargs: Any ) -> _models.ManagedInstancePrivateEndpointConnection: """Gets a private endpoint connection. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param private_endpoint_connection_name: The name of the private endpoint connection. + :param private_endpoint_connection_name: The name of the private endpoint connection. Required. :type private_endpoint_connection_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstancePrivateEndpointConnection, or the result of cls(response) + :return: ManagedInstancePrivateEndpointConnection or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstancePrivateEndpointConnection - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstancePrivateEndpointConnection] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstancePrivateEndpointConnection] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, private_endpoint_connection_name=private_endpoint_connection_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -254,49 +238,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstancePrivateEndpointConnection', pipeline_response) + deserialized = self._deserialize("ManagedInstancePrivateEndpointConnection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, private_endpoint_connection_name: str, - parameters: _models.ManagedInstancePrivateEndpointConnection, + parameters: Union[_models.ManagedInstancePrivateEndpointConnection, IO], **kwargs: Any ) -> Optional[_models.ManagedInstancePrivateEndpointConnection]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedInstancePrivateEndpointConnection]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstancePrivateEndpointConnection]] - _json = self._serialize.body(parameters, 'ManagedInstancePrivateEndpointConnection') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstancePrivateEndpointConnection") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, private_endpoint_connection_name=private_endpoint_connection_name, @@ -304,7 +290,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -312,10 +299,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -324,39 +310,118 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedInstancePrivateEndpointConnection', pipeline_response) + deserialized = self._deserialize("ManagedInstancePrivateEndpointConnection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, private_endpoint_connection_name: str, parameters: _models.ManagedInstancePrivateEndpointConnection, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ManagedInstancePrivateEndpointConnection]: """Approve or reject a private endpoint connection with a given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param private_endpoint_connection_name: + :param private_endpoint_connection_name: Required. :type private_endpoint_connection_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstancePrivateEndpointConnection - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ManagedInstancePrivateEndpointConnection + or the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstancePrivateEndpointConnection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + private_endpoint_connection_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedInstancePrivateEndpointConnection]: + """Approve or reject a private endpoint connection with a given name. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param private_endpoint_connection_name: Required. + :type private_endpoint_connection_name: str + :param parameters: Required. + :type parameters: IO + :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 ManagedInstancePrivateEndpointConnection + or the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstancePrivateEndpointConnection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + private_endpoint_connection_name: str, + parameters: Union[_models.ManagedInstancePrivateEndpointConnection, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedInstancePrivateEndpointConnection]: + """Approve or reject a private endpoint connection with a given name. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param private_endpoint_connection_name: Required. + :type private_endpoint_connection_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstancePrivateEndpointConnection 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 @@ -369,20 +434,17 @@ def begin_create_or_update( or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstancePrivateEndpointConnection] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstancePrivateEndpointConnection] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstancePrivateEndpointConnection] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -391,66 +453,55 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedInstancePrivateEndpointConnection', pipeline_response) + deserialized = self._deserialize("ManagedInstancePrivateEndpointConnection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - private_endpoint_connection_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, private_endpoint_connection_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, private_endpoint_connection_name=private_endpoint_connection_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -458,10 +509,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -471,29 +521,21 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - private_endpoint_connection_name: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, managed_instance_name: str, private_endpoint_connection_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes a private endpoint connection with a given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param private_endpoint_connection_name: + :param private_endpoint_connection_name: Required. :type private_endpoint_connection_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -504,100 +546,86 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, private_endpoint_connection_name=private_endpoint_connection_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore @distributed_trace def list_by_managed_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> Iterable[_models.ManagedInstancePrivateEndpointConnectionListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedInstancePrivateEndpointConnection"]: """Gets all private endpoint connections on a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstancePrivateEndpointConnectionListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstancePrivateEndpointConnection or the + result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstancePrivateEndpointConnectionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstancePrivateEndpointConnection] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstancePrivateEndpointConnectionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstancePrivateEndpointConnectionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_managed_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_managed_instance.metadata['url'], + template_url=self.list_by_managed_instance.metadata["url"], headers=_headers, params=_params, ) @@ -605,16 +633,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_managed_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -630,10 +649,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -643,8 +660,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_managed_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections"} # type: ignore + list_by_managed_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateEndpointConnections"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_private_link_resources_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_private_link_resources_operations.py index 1ad0ed5a68d62..05c5147348505 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_private_link_resources_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_private_link_resources_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,87 +24,78 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_managed_instance_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateLinkResources") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateLinkResources", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - managed_instance_name: str, - group_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, group_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateLinkResources/{groupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateLinkResources/{groupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "groupName": _SERIALIZER.url("group_name", group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "groupName": _SERIALIZER.url("group_name", group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedInstancePrivateLinkResourcesOperations: """ @@ -121,50 +116,41 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_managed_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> Iterable[_models.ManagedInstancePrivateLinkListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedInstancePrivateLink"]: """Gets the private link resources for SQL server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstancePrivateLinkListResult or the result - of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstancePrivateLinkListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedInstancePrivateLink or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstancePrivateLink] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstancePrivateLinkListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstancePrivateLinkListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_managed_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_managed_instance.metadata['url'], + template_url=self.list_by_managed_instance.metadata["url"], headers=_headers, params=_params, ) @@ -172,16 +158,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_managed_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -197,10 +174,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -210,56 +185,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_managed_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateLinkResources"} # type: ignore + list_by_managed_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateLinkResources"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - managed_instance_name: str, - group_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, group_name: str, **kwargs: Any ) -> _models.ManagedInstancePrivateLink: """Gets a private link resource for SQL server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param group_name: The name of the private link resource. + :param group_name: The name of the private link resource. Required. :type group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstancePrivateLink, or the result of cls(response) + :return: ManagedInstancePrivateLink or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstancePrivateLink - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstancePrivateLink] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstancePrivateLink] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, group_name=group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -267,22 +230,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstancePrivateLink', pipeline_response) + deserialized = self._deserialize("ManagedInstancePrivateLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateLinkResources/{groupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/privateLinkResources/{groupName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_tde_certificates_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_tde_certificates_operations.py index 2d7c4739a9b96..0eff6b9fb18d5 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_tde_certificates_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_tde_certificates_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod @@ -21,53 +25,46 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False -def build_create_request_initial( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - *, - json: Optional[_models.TdeCertificate] = None, - content: Any = None, - **kwargs: Any + +def build_create_request( + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/tdeCertificates") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/tdeCertificates", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) + class ManagedInstanceTdeCertificatesOperations: """ @@ -88,36 +85,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - def _create_initial( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, managed_instance_name: str, - parameters: _models.TdeCertificate, + parameters: Union[_models.TdeCertificate, IO], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'TdeCertificate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "TdeCertificate") - request = build_create_request_initial( + request = build_create_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_initial.metadata['url'], + content=_content, + template_url=self._create_initial.metadata["url"], headers=_headers, params=_params, ) @@ -125,10 +126,9 @@ def _create_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -138,29 +138,30 @@ def _create_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _create_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/tdeCertificates"} # type: ignore - + _create_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/tdeCertificates"} # type: ignore - @distributed_trace - def begin_create( # pylint: disable=inconsistent-return-statements + @overload + def begin_create( self, resource_group_name: str, managed_instance_name: str, parameters: _models.TdeCertificate, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[None]: """Creates a TDE certificate for a given server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param parameters: The requested TDE certificate to be created or updated. + :param parameters: The requested TDE certificate to be created or updated. Required. :type parameters: ~azure.mgmt.sql.models.TdeCertificate - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -171,20 +172,86 @@ def begin_create( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create( + self, + resource_group_name: str, + managed_instance_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[None]: + """Creates a TDE certificate for a given server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param parameters: The requested TDE certificate to be created or updated. Required. + :type parameters: IO + :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: + """ + + @distributed_trace + def begin_create( + self, + resource_group_name: str, + managed_instance_name: str, + parameters: Union[_models.TdeCertificate, IO], + **kwargs: Any + ) -> LROPoller[None]: + """Creates a TDE certificate for a given server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param parameters: The requested TDE certificate to be created or updated. Is either a model + type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.TdeCertificate 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. + :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: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + 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] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_initial( # type: ignore resource_group_name=resource_group_name, @@ -192,34 +259,30 @@ def begin_create( # pylint: disable=inconsistent-return-statements parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_create.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/tdeCertificates"} # type: ignore + begin_create.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/tdeCertificates"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_vulnerability_assessments_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_vulnerability_assessments_operations.py index abd61527f2d2e..863662a09f21f 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_vulnerability_assessments_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instance_vulnerability_assessments_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, managed_instance_name: str, @@ -37,33 +44,32 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( @@ -71,46 +77,40 @@ def build_create_or_update_request( managed_instance_name: str, vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], subscription_id: str, - *, - json: Optional[_models.ManagedInstanceVulnerabilityAssessment] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_delete_request( @@ -122,64 +122,59 @@ def build_delete_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_instance_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedInstanceVulnerabilityAssessmentsOperations: """ @@ -200,7 +195,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -212,40 +206,35 @@ def get( """Gets the managed instance's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param managed_instance_name: The name of the managed instance for which the vulnerability - assessment is defined. + assessment is defined. Required. :type managed_instance_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstanceVulnerabilityAssessment, or the result of cls(response) + :return: ManagedInstanceVulnerabilityAssessment or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceVulnerabilityAssessment - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceVulnerabilityAssessment] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceVulnerabilityAssessment] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -253,33 +242,33 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstanceVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("ManagedInstanceVulnerabilityAssessment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, managed_instance_name: str, vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], parameters: _models.ManagedInstanceVulnerabilityAssessment, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.ManagedInstanceVulnerabilityAssessment: """Creates or updates the managed instance's vulnerability assessment. Learn more about setting @@ -287,36 +276,109 @@ def create_or_update( https://docs.microsoft.com/azure/azure-sql/database/sql-database-vulnerability-assessment-storage. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param managed_instance_name: The name of the managed instance for which the vulnerability - assessment is defined. + assessment is defined. Required. :type managed_instance_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param parameters: The requested resource. + :param parameters: The requested resource. Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstanceVulnerabilityAssessment - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: ManagedInstanceVulnerabilityAssessment, or the result of cls(response) + :return: ManagedInstanceVulnerabilityAssessment or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstanceVulnerabilityAssessment - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.ManagedInstanceVulnerabilityAssessment: + """Creates or updates the managed instance's vulnerability assessment. Learn more about setting + SQL vulnerability assessment with managed identity - + https://docs.microsoft.com/azure/azure-sql/database/sql-database-vulnerability-assessment-storage. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance for which the vulnerability + assessment is defined. Required. + :type managed_instance_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param parameters: The requested resource. Required. + :type parameters: IO + :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: ManagedInstanceVulnerabilityAssessment or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedInstanceVulnerabilityAssessment + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + parameters: Union[_models.ManagedInstanceVulnerabilityAssessment, IO], + **kwargs: Any + ) -> _models.ManagedInstanceVulnerabilityAssessment: + """Creates or updates the managed instance's vulnerability assessment. Learn more about setting + SQL vulnerability assessment with managed identity - + https://docs.microsoft.com/azure/azure-sql/database/sql-database-vulnerability-assessment-storage. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance for which the vulnerability + assessment is defined. Required. + :type managed_instance_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param parameters: The requested resource. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceVulnerabilityAssessment 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 + :return: ManagedInstanceVulnerabilityAssessment or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ManagedInstanceVulnerabilityAssessment + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceVulnerabilityAssessment] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceVulnerabilityAssessment] - _json = self._serialize.body(parameters, 'ManagedInstanceVulnerabilityAssessment') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceVulnerabilityAssessment") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -326,7 +388,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -334,10 +397,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -345,18 +407,17 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('ManagedInstanceVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("ManagedInstanceVulnerabilityAssessment", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedInstanceVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("ManagedInstanceVulnerabilityAssessment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -369,40 +430,35 @@ def delete( # pylint: disable=inconsistent-return-statements """Removes the managed instance's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param managed_instance_name: The name of the managed instance for which the vulnerability - assessment is defined. + assessment is defined. Required. :type managed_instance_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -410,10 +466,9 @@ def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -423,53 +478,45 @@ def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> Iterable[_models.ManagedInstanceVulnerabilityAssessmentListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedInstanceVulnerabilityAssessment"]: """Gets the managed instance's vulnerability assessment policies. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param managed_instance_name: The name of the managed instance for which the vulnerability - assessments is defined. + assessments is defined. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceVulnerabilityAssessmentListResult - or the result of cls(response) + :return: An iterator like instance of either ManagedInstanceVulnerabilityAssessment or the + result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceVulnerabilityAssessmentListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceVulnerabilityAssessment] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceVulnerabilityAssessmentListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceVulnerabilityAssessmentListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -477,16 +524,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -502,10 +540,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -515,8 +551,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/vulnerabilityAssessments"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instances_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instances_operations.py index 9adf93f2fc315..fada162f76f31 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instances_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_instances_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_instance_pool_request( resource_group_name: str, instance_pool_name: str, @@ -40,110 +47,89 @@ def build_list_by_instance_pool_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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}/managedInstances") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}/managedInstances", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "instancePoolName": _SERIALIZER.url("instance_pool_name", instance_pool_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "instancePoolName": _SERIALIZER.url("instance_pool_name", instance_pool_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if expand is not None: - _params['$expand'] = _SERIALIZER.query("expand", expand, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$expand"] = _SERIALIZER.query("expand", expand, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_list_request( - subscription_id: str, - *, - expand: Optional[str] = None, - **kwargs: Any -) -> HttpRequest: +def build_list_request(subscription_id: str, *, expand: Optional[str] = None, **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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/managedInstances") path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if expand is not None: - _params['$expand'] = _SERIALIZER.query("expand", expand, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$expand"] = _SERIALIZER.query("expand", expand, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_resource_group_request( - resource_group_name: str, - subscription_id: str, - *, - expand: Optional[str] = None, - **kwargs: Any + resource_group_name: str, subscription_id: str, *, expand: Optional[str] = None, **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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if expand is not None: - _params['$expand'] = _SERIALIZER.query("expand", expand, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$expand"] = _SERIALIZER.query("expand", expand, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -157,154 +143,124 @@ 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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if expand is not None: - _params['$expand'] = _SERIALIZER.query("expand", expand, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$expand"] = _SERIALIZER.query("expand", expand, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - *, - json: Optional[_models.ManagedInstance] = None, - content: Any = None, - **kwargs: Any +def build_create_or_update_request( + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_request_initial( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any +def build_delete_request( + resource_group_name: str, managed_instance_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) -def build_update_request_initial( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - *, - json: Optional[_models.ManagedInstanceUpdate] = None, - content: Any = None, - **kwargs: Any +def build_update_request( + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_managed_instance_request( @@ -324,49 +280,46 @@ def build_list_by_managed_instance_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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/topqueries") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/topqueries", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if number_of_queries is not None: - _params['numberOfQueries'] = _SERIALIZER.query("number_of_queries", number_of_queries, 'int') + _params["numberOfQueries"] = _SERIALIZER.query("number_of_queries", number_of_queries, "int") if databases is not None: - _params['databases'] = _SERIALIZER.query("databases", databases, 'str') + _params["databases"] = _SERIALIZER.query("databases", databases, "str") if start_time is not None: - _params['startTime'] = _SERIALIZER.query("start_time", start_time, 'str') + _params["startTime"] = _SERIALIZER.query("start_time", start_time, "str") if end_time is not None: - _params['endTime'] = _SERIALIZER.query("end_time", end_time, 'str') + _params["endTime"] = _SERIALIZER.query("end_time", end_time, "str") if interval is not None: - _params['interval'] = _SERIALIZER.query("interval", interval, 'str') + _params["interval"] = _SERIALIZER.query("interval", interval, "str") if aggregation_function is not None: - _params['aggregationFunction'] = _SERIALIZER.query("aggregation_function", aggregation_function, 'str') + _params["aggregationFunction"] = _SERIALIZER.query("aggregation_function", aggregation_function, "str") if observation_metric is not None: - _params['observationMetric'] = _SERIALIZER.query("observation_metric", observation_metric, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["observationMetric"] = _SERIALIZER.query("observation_metric", observation_metric, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_failover_request_initial( +def build_failover_request( resource_group_name: str, managed_instance_name: str, subscription_id: str, @@ -376,28 +329,27 @@ def build_failover_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/failover") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/failover", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if replica_type is not None: - _params['replicaType'] = _SERIALIZER.query("replica_type", replica_type, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["replicaType"] = _SERIALIZER.query("replica_type", replica_type, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) class ManagedInstancesOperations: """ @@ -418,53 +370,43 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance_pool( - self, - resource_group_name: str, - instance_pool_name: str, - expand: Optional[str] = None, - **kwargs: Any - ) -> Iterable[_models.ManagedInstanceListResult]: + self, resource_group_name: str, instance_pool_name: str, expand: Optional[str] = None, **kwargs: Any + ) -> Iterable["_models.ManagedInstance"]: """Gets a list of all managed instances in an instance pool. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param instance_pool_name: The instance pool name. + :param instance_pool_name: The instance pool name. Required. :type instance_pool_name: str :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedInstance or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstance] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_pool_request( resource_group_name=resource_group_name, instance_pool_name=instance_pool_name, subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.list_by_instance_pool.metadata['url'], + api_version=api_version, + template_url=self.list_by_instance_pool.metadata["url"], headers=_headers, params=_params, ) @@ -472,17 +414,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_pool_request( - resource_group_name=resource_group_name, - instance_pool_name=instance_pool_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - expand=expand, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -498,10 +430,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -511,49 +441,38 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_instance_pool.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}/managedInstances"} # type: ignore + list_by_instance_pool.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}/managedInstances"} # type: ignore @distributed_trace - def list( - self, - expand: Optional[str] = None, - **kwargs: Any - ) -> Iterable[_models.ManagedInstanceListResult]: + def list(self, expand: Optional[str] = None, **kwargs: Any) -> Iterable["_models.ManagedInstance"]: """Gets a list of all managed instances in the subscription. :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedInstance or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstance] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_request( subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.list.metadata['url'], + api_version=api_version, + template_url=self.list.metadata["url"], headers=_headers, params=_params, ) @@ -561,15 +480,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_request( - subscription_id=self._config.subscription_id, - api_version=api_version, - expand=expand, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -585,10 +496,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -598,54 +507,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/managedInstances"} # type: ignore + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/managedInstances"} # type: ignore @distributed_trace def list_by_resource_group( - self, - resource_group_name: str, - expand: Optional[str] = None, - **kwargs: Any - ) -> Iterable[_models.ManagedInstanceListResult]: + self, resource_group_name: str, expand: Optional[str] = None, **kwargs: Any + ) -> Iterable["_models.ManagedInstance"]: """Gets a list of managed instances in a resource group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedInstanceListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstanceListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedInstance or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedInstance] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstanceListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstanceListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_request( resource_group_name=resource_group_name, subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.list_by_resource_group.metadata['url'], + api_version=api_version, + template_url=self.list_by_resource_group.metadata["url"], headers=_headers, params=_params, ) @@ -653,16 +552,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - expand=expand, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -678,10 +568,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -691,56 +579,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances"} # type: ignore + list_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - managed_instance_name: str, - expand: Optional[str] = None, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, expand: Optional[str] = None, **kwargs: Any ) -> _models.ManagedInstance: """Gets a managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedInstance, or the result of cls(response) + :return: ManagedInstance or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedInstance - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstance] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstance] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.get.metadata['url'], + api_version=api_version, + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -748,55 +624,58 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedInstance', pipeline_response) + deserialized = self._deserialize("ManagedInstance", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, - parameters: _models.ManagedInstance, + parameters: Union[_models.ManagedInstance, IO], **kwargs: Any ) -> Optional[_models.ManagedInstance]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedInstance]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstance]] - _json = self._serialize.body(parameters, 'ManagedInstance') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstance") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -804,10 +683,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -816,39 +694,111 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedInstance', pipeline_response) + deserialized = self._deserialize("ManagedInstance", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedInstance', pipeline_response) + deserialized = self._deserialize("ManagedInstance", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, parameters: _models.ManagedInstance, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ManagedInstance]: """Creates or updates a managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param parameters: The requested managed instance resource state. + :param parameters: The requested managed instance resource state. Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstance - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ManagedInstance or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstance] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedInstance]: + """Creates or updates a managed instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param parameters: The requested managed instance resource state. Required. + :type parameters: IO + :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 ManagedInstance or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstance] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + parameters: Union[_models.ManagedInstance, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedInstance]: + """Creates or updates a managed instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param parameters: The requested managed instance resource state. Is either a model type or a + IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstance 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 @@ -860,20 +810,17 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ManagedInstance or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstance] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstance] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstance] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -881,64 +828,54 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedInstance', pipeline_response) + deserialized = self._deserialize("ManagedInstance", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -946,10 +883,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -959,26 +895,17 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> LROPoller[None]: + def begin_delete(self, resource_group_name: str, managed_instance_name: str, **kwargs: Any) -> LROPoller[None]: """Deletes a managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -989,85 +916,83 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore def _update_initial( self, resource_group_name: str, managed_instance_name: str, - parameters: _models.ManagedInstanceUpdate, + parameters: Union[_models.ManagedInstanceUpdate, IO], **kwargs: Any ) -> Optional[_models.ManagedInstance]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedInstance]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedInstance]] - _json = self._serialize.body(parameters, 'ManagedInstanceUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedInstanceUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1075,10 +1000,9 @@ def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1087,36 +1011,73 @@ def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedInstance', pipeline_response) + deserialized = self._deserialize("ManagedInstance", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore - + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore - @distributed_trace + @overload def begin_update( self, resource_group_name: str, managed_instance_name: str, parameters: _models.ManagedInstanceUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ManagedInstance]: """Updates a managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param parameters: The requested managed instance resource state. + :param parameters: The requested managed instance resource state. Required. :type parameters: ~azure.mgmt.sql.models.ManagedInstanceUpdate - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ManagedInstance or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstance] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedInstance]: + """Updates a managed instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param parameters: The requested managed instance resource state. Required. + :type parameters: IO + :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 @@ -1128,20 +1089,52 @@ def begin_update( :return: An instance of LROPoller that returns either ManagedInstance or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstance] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + parameters: Union[_models.ManagedInstanceUpdate, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedInstance]: + """Updates a managed instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param parameters: The requested managed instance resource state. Is either a model type or a + IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedInstanceUpdate 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. + :return: An instance of LROPoller that returns either ManagedInstance or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedInstance] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedInstance] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedInstance] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -1149,39 +1142,35 @@ def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedInstance', pipeline_response) + deserialized = self._deserialize("ManagedInstance", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}"} # type: ignore @distributed_trace def list_by_managed_instance( @@ -1196,15 +1185,16 @@ def list_by_managed_instance( aggregation_function: Optional[Union[str, "_models.AggregationFunctionType"]] = None, observation_metric: Optional[Union[str, "_models.MetricType"]] = None, **kwargs: Any - ) -> Iterable[_models.TopQueriesListResult]: + ) -> Iterable["_models.TopQueries"]: """Get top resource consuming queries of a managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param number_of_queries: How many 'top queries' to return. Default is 5. + :param number_of_queries: How many 'top queries' to return. Default is 5. Default value is + None. :type number_of_queries: int :param databases: Comma separated list of databases to be included into search. All DB's are included if this parameter is not specified. Default value is None. @@ -1214,39 +1204,35 @@ def list_by_managed_instance( :param end_time: End time for observed period. Default value is None. :type end_time: str :param interval: The time step to be used to summarize the metric values. Default value is - PT1H. + PT1H. Known values are: "PT1H" and "P1D". Default value is None. :type interval: str or ~azure.mgmt.sql.models.QueryTimeGrainType - :param aggregation_function: Aggregation function to be used, default value is 'sum'. + :param aggregation_function: Aggregation function to be used, default value is 'sum'. Known + values are: "avg", "min", "max", "stdev", and "sum". Default value is None. :type aggregation_function: str or ~azure.mgmt.sql.models.AggregationFunctionType - :param observation_metric: Metric to be used for ranking top queries. Default is 'cpu'. + :param observation_metric: Metric to be used for ranking top queries. Default is 'cpu'. Known + values are: "cpu", "io", "logIo", "duration", and "dtu". Default value is None. :type observation_metric: str or ~azure.mgmt.sql.models.MetricType - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either TopQueriesListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.TopQueriesListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either TopQueries or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.TopQueries] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.TopQueriesListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.TopQueriesListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_managed_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, - api_version=api_version, number_of_queries=number_of_queries, databases=databases, start_time=start_time, @@ -1254,7 +1240,8 @@ def prepare_request(next_link=None): interval=interval, aggregation_function=aggregation_function, observation_metric=observation_metric, - template_url=self.list_by_managed_instance.metadata['url'], + api_version=api_version, + template_url=self.list_by_managed_instance.metadata["url"], headers=_headers, params=_params, ) @@ -1262,23 +1249,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_managed_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - number_of_queries=number_of_queries, - databases=databases, - start_time=start_time, - end_time=end_time, - interval=interval, - aggregation_function=aggregation_function, - observation_metric=observation_metric, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1294,10 +1265,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1307,11 +1276,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_managed_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/topqueries"} # type: ignore + list_by_managed_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/topqueries"} # type: ignore def _failover_initial( # pylint: disable=inconsistent-return-statements self, @@ -1320,25 +1287,22 @@ def _failover_initial( # pylint: disable=inconsistent-return-statements replica_type: Optional[Union[str, "_models.ReplicaType"]] = None, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_failover_request_initial( + request = build_failover_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, - api_version=api_version, replica_type=replica_type, - template_url=self._failover_initial.metadata['url'], + api_version=api_version, + template_url=self._failover_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1346,10 +1310,9 @@ def _failover_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1359,11 +1322,10 @@ def _failover_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _failover_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/failover"} # type: ignore - + _failover_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/failover"} # type: ignore @distributed_trace - def begin_failover( # pylint: disable=inconsistent-return-statements + def begin_failover( self, resource_group_name: str, managed_instance_name: str, @@ -1373,15 +1335,13 @@ def begin_failover( # pylint: disable=inconsistent-return-statements """Failovers a managed instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance to failover. + :param managed_instance_name: The name of the managed instance to failover. Required. :type managed_instance_name: str - :param replica_type: The type of replica to be failed over. Default value is None. + :param replica_type: The type of replica to be failed over. Known values are: "Primary" and + "ReadableSecondary". Default value is None. :type replica_type: str or ~azure.mgmt.sql.models.ReplicaType - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1392,53 +1352,46 @@ def begin_failover( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._failover_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, replica_type=replica_type, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_failover.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/failover"} # type: ignore + begin_failover.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/failover"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_restorable_dropped_database_backup_short_term_retention_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_restorable_dropped_database_backup_short_term_retention_policies_operations.py index 3fe842854c85d..e821f8014cc4c 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_restorable_dropped_database_backup_short_term_retention_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_restorable_dropped_database_backup_short_term_retention_policies_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, managed_instance_name: str, @@ -40,132 +47,119 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "restorableDroppedDatabaseId": _SERIALIZER.url("restorable_dropped_database_id", restorable_dropped_database_id, 'str'), - "policyName": _SERIALIZER.url("policy_name", policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "restorableDroppedDatabaseId": _SERIALIZER.url( + "restorable_dropped_database_id", restorable_dropped_database_id, "str" + ), + "policyName": _SERIALIZER.url("policy_name", policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, managed_instance_name: str, restorable_dropped_database_id: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], subscription_id: str, - *, - json: Optional[_models.ManagedBackupShortTermRetentionPolicy] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "restorableDroppedDatabaseId": _SERIALIZER.url("restorable_dropped_database_id", restorable_dropped_database_id, 'str'), - "policyName": _SERIALIZER.url("policy_name", policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "restorableDroppedDatabaseId": _SERIALIZER.url( + "restorable_dropped_database_id", restorable_dropped_database_id, "str" + ), + "policyName": _SERIALIZER.url("policy_name", policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_update_request_initial( +def build_update_request( resource_group_name: str, managed_instance_name: str, restorable_dropped_database_id: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], subscription_id: str, - *, - json: Optional[_models.ManagedBackupShortTermRetentionPolicy] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "restorableDroppedDatabaseId": _SERIALIZER.url("restorable_dropped_database_id", restorable_dropped_database_id, 'str'), - "policyName": _SERIALIZER.url("policy_name", policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "restorableDroppedDatabaseId": _SERIALIZER.url( + "restorable_dropped_database_id", restorable_dropped_database_id, "str" + ), + "policyName": _SERIALIZER.url("policy_name", policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_restorable_dropped_database_request( @@ -178,33 +172,33 @@ def build_list_by_restorable_dropped_database_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "restorableDroppedDatabaseId": _SERIALIZER.url("restorable_dropped_database_id", restorable_dropped_database_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "restorableDroppedDatabaseId": _SERIALIZER.url( + "restorable_dropped_database_id", restorable_dropped_database_id, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesOperations: """ @@ -225,7 +219,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -238,34 +231,28 @@ def get( """Gets a dropped database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param restorable_dropped_database_id: + :param restorable_dropped_database_id: Required. :type restorable_dropped_database_id: str - :param policy_name: The policy name. + :param policy_name: The policy name. "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedBackupShortTermRetentionPolicy, or the result of cls(response) + :return: ManagedBackupShortTermRetentionPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, @@ -273,7 +260,7 @@ def get( policy_name=policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -281,25 +268,23 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore def _create_or_update_initial( self, @@ -307,24 +292,28 @@ def _create_or_update_initial( managed_instance_name: str, restorable_dropped_database_id: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], - parameters: _models.ManagedBackupShortTermRetentionPolicy, + parameters: Union[_models.ManagedBackupShortTermRetentionPolicy, IO], **kwargs: Any ) -> Optional[_models.ManagedBackupShortTermRetentionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedBackupShortTermRetentionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedBackupShortTermRetentionPolicy]] - _json = self._serialize.body(parameters, 'ManagedBackupShortTermRetentionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedBackupShortTermRetentionPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, restorable_dropped_database_id=restorable_dropped_database_id, @@ -333,7 +322,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -341,10 +331,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -353,17 +342,16 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, @@ -371,24 +359,111 @@ def begin_create_or_update( restorable_dropped_database_id: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], parameters: _models.ManagedBackupShortTermRetentionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ManagedBackupShortTermRetentionPolicy]: """Sets a database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param restorable_dropped_database_id: + :param restorable_dropped_database_id: Required. :type restorable_dropped_database_id: str - :param policy_name: The policy name. Should always be "default". + :param policy_name: The policy name. Should always be "default". "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName - :param parameters: The short term retention policy info. + :param parameters: The short term retention policy info. Required. :type parameters: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ManagedBackupShortTermRetentionPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + restorable_dropped_database_id: str, + policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedBackupShortTermRetentionPolicy]: + """Sets a database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param restorable_dropped_database_id: Required. + :type restorable_dropped_database_id: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Required. + :type parameters: IO + :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 ManagedBackupShortTermRetentionPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + restorable_dropped_database_id: str, + policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], + parameters: Union[_models.ManagedBackupShortTermRetentionPolicy, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedBackupShortTermRetentionPolicy]: + """Sets a database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param restorable_dropped_database_id: Required. + :type restorable_dropped_database_id: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy 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 @@ -401,20 +476,17 @@ def begin_create_or_update( the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -424,39 +496,35 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore def _update_initial( self, @@ -464,24 +532,28 @@ def _update_initial( managed_instance_name: str, restorable_dropped_database_id: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], - parameters: _models.ManagedBackupShortTermRetentionPolicy, + parameters: Union[_models.ManagedBackupShortTermRetentionPolicy, IO], **kwargs: Any ) -> Optional[_models.ManagedBackupShortTermRetentionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedBackupShortTermRetentionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedBackupShortTermRetentionPolicy]] - _json = self._serialize.body(parameters, 'ManagedBackupShortTermRetentionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedBackupShortTermRetentionPolicy") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, restorable_dropped_database_id=restorable_dropped_database_id, @@ -490,7 +562,8 @@ def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -498,10 +571,9 @@ def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -510,17 +582,16 @@ def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore - @distributed_trace + @overload def begin_update( self, resource_group_name: str, @@ -528,24 +599,26 @@ def begin_update( restorable_dropped_database_id: str, policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], parameters: _models.ManagedBackupShortTermRetentionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ManagedBackupShortTermRetentionPolicy]: """Sets a database's short term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param restorable_dropped_database_id: + :param restorable_dropped_database_id: Required. :type restorable_dropped_database_id: str - :param policy_name: The policy name. Should always be "default". + :param policy_name: The policy name. Should always be "default". "default" Required. :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName - :param parameters: The short term retention policy info. + :param parameters: The short term retention policy info. Required. :type parameters: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -558,20 +631,102 @@ def begin_update( the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + restorable_dropped_database_id: str, + policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedBackupShortTermRetentionPolicy]: + """Sets a database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param restorable_dropped_database_id: Required. + :type restorable_dropped_database_id: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Required. + :type parameters: IO + :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 ManagedBackupShortTermRetentionPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_update( + self, + resource_group_name: str, + managed_instance_name: str, + restorable_dropped_database_id: str, + policy_name: Union[str, "_models.ManagedShortTermRetentionPolicyName"], + parameters: Union[_models.ManagedBackupShortTermRetentionPolicy, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedBackupShortTermRetentionPolicy]: + """Sets a database's short term retention policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param restorable_dropped_database_id: Required. + :type restorable_dropped_database_id: str + :param policy_name: The policy name. Should always be "default". "default" Required. + :type policy_name: str or ~azure.mgmt.sql.models.ManagedShortTermRetentionPolicyName + :param parameters: The short term retention policy info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy 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. + :return: An instance of LROPoller that returns either ManagedBackupShortTermRetentionPolicy or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -581,87 +736,75 @@ def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedBackupShortTermRetentionPolicy', pipeline_response) + deserialized = self._deserialize("ManagedBackupShortTermRetentionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}"} # type: ignore @distributed_trace def list_by_restorable_dropped_database( - self, - resource_group_name: str, - managed_instance_name: str, - restorable_dropped_database_id: str, - **kwargs: Any - ) -> Iterable[_models.ManagedBackupShortTermRetentionPolicyListResult]: + self, resource_group_name: str, managed_instance_name: str, restorable_dropped_database_id: str, **kwargs: Any + ) -> Iterable["_models.ManagedBackupShortTermRetentionPolicy"]: """Gets a dropped database's short term retention policy list. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param restorable_dropped_database_id: + :param restorable_dropped_database_id: Required. :type restorable_dropped_database_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedBackupShortTermRetentionPolicyListResult or - the result of cls(response) + :return: An iterator like instance of either ManagedBackupShortTermRetentionPolicy or the + result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedBackupShortTermRetentionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedBackupShortTermRetentionPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_restorable_dropped_database_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, restorable_dropped_database_id=restorable_dropped_database_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_restorable_dropped_database.metadata['url'], + template_url=self.list_by_restorable_dropped_database.metadata["url"], headers=_headers, params=_params, ) @@ -669,17 +812,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_restorable_dropped_database_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - restorable_dropped_database_id=restorable_dropped_database_id, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -695,10 +828,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -708,8 +839,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_restorable_dropped_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies"} # type: ignore + list_by_restorable_dropped_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_server_dns_aliases_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_server_dns_aliases_operations.py index 25983eae86823..195142b395042 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_server_dns_aliases_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_server_dns_aliases_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,213 +26,174 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_managed_instance_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - managed_instance_name: str, - dns_alias_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, dns_alias_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "dnsAliasName": _SERIALIZER.url("dns_alias_name", dns_alias_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "dnsAliasName": _SERIALIZER.url("dns_alias_name", dns_alias_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - resource_group_name: str, - managed_instance_name: str, - dns_alias_name: str, - subscription_id: str, - *, - json: Optional[_models.ManagedServerDnsAliasCreation] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, managed_instance_name: str, dns_alias_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "dnsAliasName": _SERIALIZER.url("dns_alias_name", dns_alias_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "dnsAliasName": _SERIALIZER.url("dns_alias_name", dns_alias_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) - - -def build_delete_request_initial( - resource_group_name: str, - managed_instance_name: str, - dns_alias_name: str, - subscription_id: str, - **kwargs: Any + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_delete_request( + resource_group_name: str, managed_instance_name: str, dns_alias_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "dnsAliasName": _SERIALIZER.url("dns_alias_name", dns_alias_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "dnsAliasName": _SERIALIZER.url("dns_alias_name", dns_alias_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') - - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) - - -def build_acquire_request_initial( - resource_group_name: str, - managed_instance_name: str, - dns_alias_name: str, - subscription_id: str, - *, - json: Optional[_models.ManagedServerDnsAliasAcquisition] = None, - content: Any = None, - **kwargs: Any + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) + + +def build_acquire_request( + resource_group_name: str, managed_instance_name: str, dns_alias_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}/acquire") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}/acquire", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "dnsAliasName": _SERIALIZER.url("dns_alias_name", dns_alias_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "dnsAliasName": _SERIALIZER.url("dns_alias_name", dns_alias_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) + class ManagedServerDnsAliasesOperations: """ @@ -249,49 +214,41 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_managed_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> Iterable[_models.ManagedServerDnsAliasListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedServerDnsAlias"]: """Gets a list of managed server DNS aliases for a managed server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedServerDnsAliasListResult or the result of + :return: An iterator like instance of either ManagedServerDnsAlias or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedServerDnsAliasListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedServerDnsAlias] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedServerDnsAliasListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedServerDnsAliasListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_managed_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_managed_instance.metadata['url'], + template_url=self.list_by_managed_instance.metadata["url"], headers=_headers, params=_params, ) @@ -299,16 +256,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_managed_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -324,10 +272,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -337,56 +283,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_managed_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases"} # type: ignore + list_by_managed_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - managed_instance_name: str, - dns_alias_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, dns_alias_name: str, **kwargs: Any ) -> _models.ManagedServerDnsAlias: """Gets a server DNS alias. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param dns_alias_name: + :param dns_alias_name: Required. :type dns_alias_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedServerDnsAlias, or the result of cls(response) + :return: ManagedServerDnsAlias or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedServerDnsAlias - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedServerDnsAlias] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedServerDnsAlias] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, dns_alias_name=dns_alias_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -394,49 +328,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ManagedServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, dns_alias_name: str, - parameters: _models.ManagedServerDnsAliasCreation, + parameters: Union[_models.ManagedServerDnsAliasCreation, IO], **kwargs: Any ) -> Optional[_models.ManagedServerDnsAlias]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedServerDnsAlias]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedServerDnsAlias]] - _json = self._serialize.body(parameters, 'ManagedServerDnsAliasCreation') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedServerDnsAliasCreation") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, dns_alias_name=dns_alias_name, @@ -444,7 +380,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -452,10 +389,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -464,42 +400,82 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ManagedServerDnsAlias", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ManagedServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ManagedServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, dns_alias_name: str, parameters: _models.ManagedServerDnsAliasCreation, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ManagedServerDnsAlias]: """Creates a managed server DNS alias. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param dns_alias_name: + :param dns_alias_name: Required. :type dns_alias_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.ManagedServerDnsAliasCreation - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ManagedServerDnsAlias or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedServerDnsAlias] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + dns_alias_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedServerDnsAlias]: + """Creates a managed server DNS alias. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param dns_alias_name: Required. + :type dns_alias_name: str + :param parameters: Required. + :type parameters: IO + :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 @@ -511,20 +487,54 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ManagedServerDnsAlias or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedServerDnsAlias] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + dns_alias_name: str, + parameters: Union[_models.ManagedServerDnsAliasCreation, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedServerDnsAlias]: + """Creates a managed server DNS alias. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param dns_alias_name: Required. + :type dns_alias_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedServerDnsAliasCreation 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. + :return: An instance of LROPoller that returns either ManagedServerDnsAlias or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedServerDnsAlias] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedServerDnsAlias] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedServerDnsAlias] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -533,66 +543,55 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ManagedServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - dns_alias_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, dns_alias_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, dns_alias_name=dns_alias_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -600,10 +599,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -613,29 +611,21 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - dns_alias_name: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, managed_instance_name: str, dns_alias_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes the managed server DNS alias with the given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param dns_alias_name: + :param dns_alias_name: Required. :type dns_alias_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -646,80 +636,77 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, dns_alias_name=dns_alias_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}"} # type: ignore def _acquire_initial( self, resource_group_name: str, managed_instance_name: str, dns_alias_name: str, - parameters: _models.ManagedServerDnsAliasAcquisition, + parameters: Union[_models.ManagedServerDnsAliasAcquisition, IO], **kwargs: Any ) -> Optional[_models.ManagedServerDnsAlias]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedServerDnsAlias]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedServerDnsAlias]] - _json = self._serialize.body(parameters, 'ManagedServerDnsAliasAcquisition') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedServerDnsAliasAcquisition") - request = build_acquire_request_initial( + request = build_acquire_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, dns_alias_name=dns_alias_name, @@ -727,7 +714,8 @@ def _acquire_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._acquire_initial.metadata['url'], + content=_content, + template_url=self._acquire_initial.metadata["url"], headers=_headers, params=_params, ) @@ -735,10 +723,9 @@ def _acquire_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -747,39 +734,40 @@ def _acquire_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ManagedServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _acquire_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}/acquire"} # type: ignore - + _acquire_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}/acquire"} # type: ignore - @distributed_trace + @overload def begin_acquire( self, resource_group_name: str, managed_instance_name: str, dns_alias_name: str, parameters: _models.ManagedServerDnsAliasAcquisition, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ManagedServerDnsAlias]: """Acquires managed server DNS alias from another managed server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param dns_alias_name: + :param dns_alias_name: Required. :type dns_alias_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.ManagedServerDnsAliasAcquisition - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -791,20 +779,93 @@ def begin_acquire( :return: An instance of LROPoller that returns either ManagedServerDnsAlias or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedServerDnsAlias] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_acquire( + self, + resource_group_name: str, + managed_instance_name: str, + dns_alias_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedServerDnsAlias]: + """Acquires managed server DNS alias from another managed server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param dns_alias_name: Required. + :type dns_alias_name: str + :param parameters: Required. + :type parameters: IO + :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 ManagedServerDnsAlias or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedServerDnsAlias] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_acquire( + self, + resource_group_name: str, + managed_instance_name: str, + dns_alias_name: str, + parameters: Union[_models.ManagedServerDnsAliasAcquisition, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedServerDnsAlias]: + """Acquires managed server DNS alias from another managed server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param dns_alias_name: Required. + :type dns_alias_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedServerDnsAliasAcquisition 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. + :return: An instance of LROPoller that returns either ManagedServerDnsAlias or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedServerDnsAlias] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedServerDnsAlias] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedServerDnsAlias] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._acquire_initial( # type: ignore resource_group_name=resource_group_name, @@ -813,36 +874,32 @@ def begin_acquire( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ManagedServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_acquire.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}/acquire"} # type: ignore + begin_acquire.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/dnsAliases/{dnsAliasName}/acquire"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_server_security_alert_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_server_security_alert_policies_operations.py index 21a7c3f248078..9bf7809f880eb 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_server_security_alert_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_managed_server_security_alert_policies_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, managed_instance_name: str, @@ -39,117 +46,101 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies/{securityAlertPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies/{securityAlertPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "securityAlertPolicyName": _SERIALIZER.url("security_alert_policy_name", security_alert_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "securityAlertPolicyName": _SERIALIZER.url("security_alert_policy_name", security_alert_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, managed_instance_name: str, security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], subscription_id: str, - *, - json: Optional[_models.ManagedServerSecurityAlertPolicy] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies/{securityAlertPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies/{securityAlertPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "securityAlertPolicyName": _SERIALIZER.url("security_alert_policy_name", security_alert_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "securityAlertPolicyName": _SERIALIZER.url("security_alert_policy_name", security_alert_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_instance_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ManagedServerSecurityAlertPoliciesOperations: """ @@ -170,7 +161,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -182,39 +172,33 @@ def get( """Get a managed server's threat detection policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param security_alert_policy_name: The name of the security alert policy. + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ManagedServerSecurityAlertPolicy, or the result of cls(response) + :return: ManagedServerSecurityAlertPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ManagedServerSecurityAlertPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedServerSecurityAlertPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedServerSecurityAlertPolicy] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, security_alert_policy_name=security_alert_policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -222,49 +206,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ManagedServerSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ManagedServerSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], - parameters: _models.ManagedServerSecurityAlertPolicy, + parameters: Union[_models.ManagedServerSecurityAlertPolicy, IO], **kwargs: Any ) -> Optional[_models.ManagedServerSecurityAlertPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ManagedServerSecurityAlertPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ManagedServerSecurityAlertPolicy]] - _json = self._serialize.body(parameters, 'ManagedServerSecurityAlertPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ManagedServerSecurityAlertPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, security_alert_policy_name=security_alert_policy_name, @@ -272,7 +258,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -280,10 +267,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -292,39 +278,40 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ManagedServerSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ManagedServerSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], parameters: _models.ManagedServerSecurityAlertPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ManagedServerSecurityAlertPolicy]: """Creates or updates a threat detection policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param security_alert_policy_name: The name of the security alert policy. + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName - :param parameters: The managed server security alert policy. + :param parameters: The managed server security alert policy. Required. :type parameters: ~azure.mgmt.sql.models.ManagedServerSecurityAlertPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -336,20 +323,94 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ManagedServerSecurityAlertPolicy or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedServerSecurityAlertPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ManagedServerSecurityAlertPolicy]: + """Creates or updates a threat detection policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. + :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName + :param parameters: The managed server security alert policy. Required. + :type parameters: IO + :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 ManagedServerSecurityAlertPolicy or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedServerSecurityAlertPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], + parameters: Union[_models.ManagedServerSecurityAlertPolicy, IO], + **kwargs: Any + ) -> LROPoller[_models.ManagedServerSecurityAlertPolicy]: + """Creates or updates a threat detection policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. + :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName + :param parameters: The managed server security alert policy. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.ManagedServerSecurityAlertPolicy 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. + :return: An instance of LROPoller that returns either ManagedServerSecurityAlertPolicy or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ManagedServerSecurityAlertPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedServerSecurityAlertPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedServerSecurityAlertPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -358,83 +419,71 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ManagedServerSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ManagedServerSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> Iterable[_models.ManagedServerSecurityAlertPolicyListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.ManagedServerSecurityAlertPolicy"]: """Get the managed server's threat detection policies. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ManagedServerSecurityAlertPolicyListResult or the - result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedServerSecurityAlertPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ManagedServerSecurityAlertPolicy or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ManagedServerSecurityAlertPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ManagedServerSecurityAlertPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ManagedServerSecurityAlertPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -442,16 +491,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -467,10 +507,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -480,8 +518,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/securityAlertPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_operations.py index 69b97f5a2b949..6b141d0458897 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,38 +24,34 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False -def build_list_request( - **kwargs: Any -) -> HttpRequest: + +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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL _url = kwargs.pop("template_url", "/providers/Microsoft.Sql/operations") # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class Operations: """ @@ -72,38 +72,30 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace - def list( - self, - **kwargs: Any - ) -> Iterable[_models.OperationListResult]: + def list(self, **kwargs: Any) -> Iterable["_models.Operation"]: """Lists all of the available SQL Rest API operations. - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either OperationListResult or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.OperationListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Operation or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.Operation] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.OperationListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.OperationListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_request( api_version=api_version, - template_url=self.list.metadata['url'], + template_url=self.list.metadata["url"], headers=_headers, params=_params, ) @@ -111,13 +103,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_request( - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -133,10 +119,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -146,8 +130,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list.metadata = {'url': "/providers/Microsoft.Sql/operations"} # type: ignore + list.metadata = {"url": "/providers/Microsoft.Sql/operations"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_outbound_firewall_rules_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_outbound_firewall_rules_operations.py index 5c8f38e23e2f8..abe543409d9bd 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_outbound_firewall_rules_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_outbound_firewall_rules_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,166 +26,139 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( - resource_group_name: str, - server_name: str, - outbound_rule_fqdn: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, outbound_rule_fqdn: str, subscription_id: str, **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', "2021-02-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "outboundRuleFqdn": _SERIALIZER.url("outbound_rule_fqdn", outbound_rule_fqdn, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "outboundRuleFqdn": _SERIALIZER.url("outbound_rule_fqdn", outbound_rule_fqdn, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - resource_group_name: str, - server_name: str, - outbound_rule_fqdn: str, - subscription_id: str, - *, - json: Optional[_models.OutboundFirewallRule] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, server_name: str, outbound_rule_fqdn: str, subscription_id: str, **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', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "outboundRuleFqdn": _SERIALIZER.url("outbound_rule_fqdn", outbound_rule_fqdn, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "outboundRuleFqdn": _SERIALIZER.url("outbound_rule_fqdn", outbound_rule_fqdn, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) - - -def build_delete_request_initial( - resource_group_name: str, - server_name: str, - outbound_rule_fqdn: str, - subscription_id: str, - **kwargs: Any + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_delete_request( + resource_group_name: str, server_name: str, outbound_rule_fqdn: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "outboundRuleFqdn": _SERIALIZER.url("outbound_rule_fqdn", outbound_rule_fqdn, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "outboundRuleFqdn": _SERIALIZER.url("outbound_rule_fqdn", outbound_rule_fqdn, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2021-02-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class OutboundFirewallRulesOperations: """ @@ -202,51 +179,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - outbound_rule_fqdn: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, outbound_rule_fqdn: str, **kwargs: Any ) -> _models.OutboundFirewallRule: """Gets an outbound firewall rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param outbound_rule_fqdn: + :param outbound_rule_fqdn: Required. :type outbound_rule_fqdn: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: OutboundFirewallRule, or the result of cls(response) + :return: OutboundFirewallRule or the result of cls(response) :rtype: ~azure.mgmt.sql.models.OutboundFirewallRule - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.OutboundFirewallRule] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.OutboundFirewallRule] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, outbound_rule_fqdn=outbound_rule_fqdn, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -254,49 +220,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('OutboundFirewallRule', pipeline_response) + deserialized = self._deserialize("OutboundFirewallRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, outbound_rule_fqdn: str, - parameters: _models.OutboundFirewallRule, + parameters: Union[_models.OutboundFirewallRule, IO], **kwargs: Any ) -> Optional[_models.OutboundFirewallRule]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.OutboundFirewallRule]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.OutboundFirewallRule]] - _json = self._serialize.body(parameters, 'OutboundFirewallRule') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "OutboundFirewallRule") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, outbound_rule_fqdn=outbound_rule_fqdn, @@ -304,7 +272,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -312,10 +281,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -324,42 +292,82 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('OutboundFirewallRule', pipeline_response) + deserialized = self._deserialize("OutboundFirewallRule", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('OutboundFirewallRule', pipeline_response) + deserialized = self._deserialize("OutboundFirewallRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, outbound_rule_fqdn: str, parameters: _models.OutboundFirewallRule, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.OutboundFirewallRule]: """Create a outbound firewall rule with a given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param outbound_rule_fqdn: + :param outbound_rule_fqdn: Required. :type outbound_rule_fqdn: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.OutboundFirewallRule - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 OutboundFirewallRule or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.OutboundFirewallRule] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + outbound_rule_fqdn: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.OutboundFirewallRule]: + """Create a outbound firewall rule with a given name. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param outbound_rule_fqdn: Required. + :type outbound_rule_fqdn: str + :param parameters: Required. + :type parameters: IO + :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 @@ -371,20 +379,54 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either OutboundFirewallRule or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.OutboundFirewallRule] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + outbound_rule_fqdn: str, + parameters: Union[_models.OutboundFirewallRule, IO], + **kwargs: Any + ) -> LROPoller[_models.OutboundFirewallRule]: + """Create a outbound firewall rule with a given name. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param outbound_rule_fqdn: Required. + :type outbound_rule_fqdn: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.OutboundFirewallRule 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. + :return: An instance of LROPoller that returns either OutboundFirewallRule or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.OutboundFirewallRule] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.OutboundFirewallRule] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.OutboundFirewallRule] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -393,66 +435,55 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('OutboundFirewallRule', pipeline_response) + deserialized = self._deserialize("OutboundFirewallRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - outbound_rule_fqdn: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, outbound_rule_fqdn: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, outbound_rule_fqdn=outbound_rule_fqdn, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -460,10 +491,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -473,29 +503,21 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - outbound_rule_fqdn: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, server_name: str, outbound_rule_fqdn: str, **kwargs: Any ) -> LROPoller[None]: """Deletes a outbound firewall rule with a given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param outbound_rule_fqdn: + :param outbound_rule_fqdn: Required. :type outbound_rule_fqdn: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -506,99 +528,85 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, outbound_rule_fqdn=outbound_rule_fqdn, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules/{outboundRuleFqdn}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.OutboundFirewallRuleListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.OutboundFirewallRule"]: """Gets all outbound firewall rules on a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either OutboundFirewallRuleListResult or the result of + :return: An iterator like instance of either OutboundFirewallRule or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.OutboundFirewallRuleListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.OutboundFirewallRule] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.OutboundFirewallRuleListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.OutboundFirewallRuleListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -606,16 +614,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -631,10 +630,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -644,8 +641,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/outboundFirewallRules"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_patch.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_patch.py index 0ad201a8c586e..f7dd32510333d 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_patch.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_patch.py @@ -10,6 +10,7 @@ __all__: List[str] = [] # Add all objects you want publicly available to users at this package level + def patch_sdk(): """Do not remove from this file. diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_private_endpoint_connections_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_private_endpoint_connections_operations.py index 5af7acb870964..17865107f47ea 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_private_endpoint_connections_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_private_endpoint_connections_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -39,83 +46,76 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "privateEndpointConnectionName": _SERIALIZER.url("private_endpoint_connection_name", private_endpoint_connection_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "privateEndpointConnectionName": _SERIALIZER.url( + "private_endpoint_connection_name", private_endpoint_connection_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, server_name: str, private_endpoint_connection_name: str, subscription_id: str, - *, - json: Optional[_models.PrivateEndpointConnection] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "privateEndpointConnectionName": _SERIALIZER.url("private_endpoint_connection_name", private_endpoint_connection_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "privateEndpointConnectionName": _SERIALIZER.url( + "private_endpoint_connection_name", private_endpoint_connection_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_request_initial( +def build_delete_request( resource_group_name: str, server_name: str, private_endpoint_connection_name: str, @@ -124,64 +124,59 @@ def build_delete_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "privateEndpointConnectionName": _SERIALIZER.url("private_endpoint_connection_name", private_endpoint_connection_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "privateEndpointConnectionName": _SERIALIZER.url( + "private_endpoint_connection_name", private_endpoint_connection_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class PrivateEndpointConnectionsOperations: """ @@ -202,51 +197,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - private_endpoint_connection_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, private_endpoint_connection_name: str, **kwargs: Any ) -> _models.PrivateEndpointConnection: """Gets a private endpoint connection. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param private_endpoint_connection_name: The name of the private endpoint connection. + :param private_endpoint_connection_name: The name of the private endpoint connection. Required. :type private_endpoint_connection_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: PrivateEndpointConnection, or the result of cls(response) + :return: PrivateEndpointConnection or the result of cls(response) :rtype: ~azure.mgmt.sql.models.PrivateEndpointConnection - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.PrivateEndpointConnection] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.PrivateEndpointConnection] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, private_endpoint_connection_name=private_endpoint_connection_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -254,49 +238,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('PrivateEndpointConnection', pipeline_response) + deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, private_endpoint_connection_name: str, - parameters: _models.PrivateEndpointConnection, + parameters: Union[_models.PrivateEndpointConnection, IO], **kwargs: Any ) -> Optional[_models.PrivateEndpointConnection]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.PrivateEndpointConnection]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.PrivateEndpointConnection]] - _json = self._serialize.body(parameters, 'PrivateEndpointConnection') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "PrivateEndpointConnection") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, private_endpoint_connection_name=private_endpoint_connection_name, @@ -304,7 +290,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -312,10 +299,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -324,39 +310,116 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('PrivateEndpointConnection', pipeline_response) + deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, private_endpoint_connection_name: str, parameters: _models.PrivateEndpointConnection, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.PrivateEndpointConnection]: """Approve or reject a private endpoint connection with a given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param private_endpoint_connection_name: + :param private_endpoint_connection_name: Required. :type private_endpoint_connection_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.PrivateEndpointConnection - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 PrivateEndpointConnection or the result + of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.PrivateEndpointConnection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + private_endpoint_connection_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.PrivateEndpointConnection]: + """Approve or reject a private endpoint connection with a given name. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param private_endpoint_connection_name: Required. + :type private_endpoint_connection_name: str + :param parameters: Required. + :type parameters: IO + :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 PrivateEndpointConnection or the result + of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.PrivateEndpointConnection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + private_endpoint_connection_name: str, + parameters: Union[_models.PrivateEndpointConnection, IO], + **kwargs: Any + ) -> LROPoller[_models.PrivateEndpointConnection]: + """Approve or reject a private endpoint connection with a given name. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param private_endpoint_connection_name: Required. + :type private_endpoint_connection_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.PrivateEndpointConnection 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 @@ -368,20 +431,17 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either PrivateEndpointConnection or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.PrivateEndpointConnection] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.PrivateEndpointConnection] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.PrivateEndpointConnection] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -390,66 +450,55 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('PrivateEndpointConnection', pipeline_response) + deserialized = self._deserialize("PrivateEndpointConnection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - private_endpoint_connection_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, private_endpoint_connection_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, private_endpoint_connection_name=private_endpoint_connection_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -457,10 +506,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -470,29 +518,21 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - private_endpoint_connection_name: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, server_name: str, private_endpoint_connection_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes a private endpoint connection with a given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param private_endpoint_connection_name: + :param private_endpoint_connection_name: Required. :type private_endpoint_connection_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -503,100 +543,85 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, private_endpoint_connection_name=private_endpoint_connection_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.PrivateEndpointConnectionListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.PrivateEndpointConnection"]: """Gets all private endpoint connections on a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PrivateEndpointConnectionListResult or the result - of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.PrivateEndpointConnectionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either PrivateEndpointConnection or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.PrivateEndpointConnection] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.PrivateEndpointConnectionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.PrivateEndpointConnectionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -604,16 +629,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -629,10 +645,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -642,8 +656,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateEndpointConnections"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_private_link_resources_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_private_link_resources_operations.py index 742f91195a44a..5f36edff3b97f 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_private_link_resources_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_private_link_resources_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,87 +24,78 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateLinkResources") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateLinkResources", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - server_name: str, - group_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, group_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateLinkResources/{groupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateLinkResources/{groupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "groupName": _SERIALIZER.url("group_name", group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "groupName": _SERIALIZER.url("group_name", group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class PrivateLinkResourcesOperations: """ @@ -121,49 +116,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.PrivateLinkResourceListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.PrivateLinkResource"]: """Gets the private link resources for SQL server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PrivateLinkResourceListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.PrivateLinkResourceListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either PrivateLinkResource or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.PrivateLinkResource] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.PrivateLinkResourceListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.PrivateLinkResourceListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -171,16 +157,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -196,10 +173,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -209,56 +184,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateLinkResources"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateLinkResources"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, group_name: str, **kwargs: Any ) -> _models.PrivateLinkResource: """Gets a private link resource for SQL server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param group_name: The name of the private link resource. + :param group_name: The name of the private link resource. Required. :type group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: PrivateLinkResource, or the result of cls(response) + :return: PrivateLinkResource or the result of cls(response) :rtype: ~azure.mgmt.sql.models.PrivateLinkResource - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.PrivateLinkResource] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.PrivateLinkResource] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, group_name=group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -266,22 +229,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('PrivateLinkResource', pipeline_response) + deserialized = self._deserialize("PrivateLinkResource", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateLinkResources/{groupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/privateLinkResources/{groupName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_recommended_sensitivity_labels_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_recommended_sensitivity_labels_operations.py index bd11203cc2231..2b67e1b962cc6 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_recommended_sensitivity_labels_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_recommended_sensitivity_labels_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse from azure.core.rest import HttpRequest @@ -19,55 +23,47 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_update_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - *, - json: Optional[_models.RecommendedSensitivityLabelUpdateList] = None, - content: Any = None, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/recommendedSensitivityLabels") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/recommendedSensitivityLabels", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) + class RecommendedSensitivityLabelsOperations: """ @@ -88,48 +84,113 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace + @overload def update( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.RecommendedSensitivityLabelUpdateList, + *, + content_type: str = "application/json", **kwargs: Any ) -> None: """Update recommended sensitivity labels states of a given database using an operations batch. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.RecommendedSensitivityLabelUpdateList - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + def update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> None: + """Update recommended sensitivity labels states of a given database using an operations batch. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Required. + :type parameters: IO + :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: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.RecommendedSensitivityLabelUpdateList, IO], + **kwargs: Any + ) -> None: + """Update recommended sensitivity labels states of a given database using an operations batch. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.RecommendedSensitivityLabelUpdateList 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 + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'RecommendedSensitivityLabelUpdateList') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "RecommendedSensitivityLabelUpdateList") request = build_update_request( resource_group_name=resource_group_name, @@ -139,7 +200,8 @@ def update( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -147,10 +209,9 @@ def update( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -160,5 +221,4 @@ def update( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/recommendedSensitivityLabels"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/recommendedSensitivityLabels"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_recoverable_databases_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_recoverable_databases_operations.py index 065bca927ddfd..e96ab5f8eb6a4 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_recoverable_databases_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_recoverable_databases_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,87 +24,78 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( - subscription_id: str, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2014-04-01")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/recoverableDatabases/{databaseName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/recoverableDatabases/{databaseName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_server_request( - subscription_id: str, - resource_group_name: str, - server_name: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2014-04-01")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/recoverableDatabases") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/recoverableDatabases", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class RecoverableDatabasesOperations: """ @@ -121,51 +116,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any ) -> _models.RecoverableDatabase: """Gets a recoverable database, which is a resource representing a database's geo backup. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: RecoverableDatabase, or the result of cls(response) + :return: RecoverableDatabase or the result of cls(response) :rtype: ~azure.mgmt.sql.models.RecoverableDatabase - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RecoverableDatabase] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RecoverableDatabase] - request = build_get_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -173,68 +157,58 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('RecoverableDatabase', pipeline_response) + deserialized = self._deserialize("RecoverableDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/recoverableDatabases/{databaseName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/recoverableDatabases/{databaseName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.RecoverableDatabaseListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.RecoverableDatabase"]: """Gets a list of recoverable databases. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either RecoverableDatabaseListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.RecoverableDatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either RecoverableDatabase or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.RecoverableDatabase] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RecoverableDatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RecoverableDatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -242,16 +216,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -267,10 +232,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -280,8 +243,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/recoverableDatabases"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/recoverableDatabases"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_recoverable_managed_databases_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_recoverable_managed_databases_operations.py index 906d173a95bb7..0142da7a0922a 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_recoverable_managed_databases_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_recoverable_managed_databases_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,48 +24,45 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_instance_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/recoverableDatabases") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/recoverableDatabases", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -74,33 +75,31 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/recoverableDatabases/{recoverableDatabaseName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/recoverableDatabases/{recoverableDatabaseName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "recoverableDatabaseName": _SERIALIZER.url("recoverable_database_name", recoverable_database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "recoverableDatabaseName": _SERIALIZER.url("recoverable_database_name", recoverable_database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class RecoverableManagedDatabasesOperations: """ @@ -121,50 +120,41 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> Iterable[_models.RecoverableManagedDatabaseListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.RecoverableManagedDatabase"]: """Gets a list of recoverable managed databases. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either RecoverableManagedDatabaseListResult or the result - of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.RecoverableManagedDatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either RecoverableManagedDatabase or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.RecoverableManagedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RecoverableManagedDatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RecoverableManagedDatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -172,16 +162,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -197,10 +178,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -210,56 +189,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/recoverableDatabases"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/recoverableDatabases"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - managed_instance_name: str, - recoverable_database_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, recoverable_database_name: str, **kwargs: Any ) -> _models.RecoverableManagedDatabase: """Gets a recoverable managed database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param recoverable_database_name: + :param recoverable_database_name: Required. :type recoverable_database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: RecoverableManagedDatabase, or the result of cls(response) + :return: RecoverableManagedDatabase or the result of cls(response) :rtype: ~azure.mgmt.sql.models.RecoverableManagedDatabase - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RecoverableManagedDatabase] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RecoverableManagedDatabase] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, recoverable_database_name=recoverable_database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -267,22 +234,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('RecoverableManagedDatabase', pipeline_response) + deserialized = self._deserialize("RecoverableManagedDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/recoverableDatabases/{recoverableDatabaseName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/recoverableDatabases/{recoverableDatabaseName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_replication_links_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_replication_links_operations.py index f8e73550ca642..e19e20e421a8b 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_replication_links_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_replication_links_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,244 +26,204 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_database_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - server_name: str, - database_name: str, - link_id: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, link_id: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "linkId": _SERIALIZER.url("link_id", link_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "linkId": _SERIALIZER.url("link_id", link_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_delete_request( - resource_group_name: str, - server_name: str, - database_name: str, - link_id: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, link_id: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "linkId": _SERIALIZER.url("link_id", link_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "linkId": _SERIALIZER.url("link_id", link_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') - - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) - - -def build_failover_request_initial( - resource_group_name: str, - server_name: str, - database_name: str, - link_id: str, - subscription_id: str, - **kwargs: Any + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) + + +def build_failover_request( + resource_group_name: str, server_name: str, database_name: str, link_id: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/failover") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/failover", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "linkId": _SERIALIZER.url("link_id", link_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "linkId": _SERIALIZER.url("link_id", link_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_failover_allow_data_loss_request_initial( - resource_group_name: str, - server_name: str, - database_name: str, - link_id: str, - subscription_id: str, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_failover_allow_data_loss_request( + resource_group_name: str, server_name: str, database_name: str, link_id: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/forceFailoverAllowDataLoss") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/forceFailoverAllowDataLoss", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "linkId": _SERIALIZER.url("link_id", link_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "linkId": _SERIALIZER.url("link_id", link_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2022-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/replicationLinks") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/replicationLinks", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ReplicationLinksOperations: """ @@ -280,53 +244,43 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.ReplicationLinkListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.ReplicationLink"]: """Gets a list of replication links on database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ReplicationLinkListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ReplicationLinkListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ReplicationLink or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ReplicationLink] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ReplicationLinkListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ReplicationLinkListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -334,17 +288,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -360,10 +304,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -373,52 +315,39 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - link_id: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, link_id: str, **kwargs: Any ) -> _models.ReplicationLink: """Gets a replication link. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param link_id: The name of the replication link. + :param link_id: The name of the replication link. Required. :type link_id: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ReplicationLink, or the result of cls(response) + :return: ReplicationLink or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ReplicationLink - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ReplicationLink] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ReplicationLink] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -426,7 +355,7 @@ def get( link_id=link_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -434,66 +363,36 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ReplicationLink', pipeline_response) + deserialized = self._deserialize("ReplicationLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}"} # type: ignore - @distributed_trace - def delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - link_id: str, - **kwargs: Any + def _delete_initial( # pylint: disable=inconsistent-return-statements + self, resource_group_name: str, server_name: str, database_name: str, link_id: str, **kwargs: Any ) -> None: - """Deletes the replication link. - - :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. - :type resource_group_name: str - :param server_name: The name of the server. - :type server_name: str - :param database_name: The name of the database. - :type database_name: str - :param link_id: - :type link_id: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -501,7 +400,7 @@ def delete( # pylint: disable=inconsistent-return-statements link_id=link_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -509,50 +408,110 @@ def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response - if response.status_code not in [200]: + if response.status_code not in [200, 202]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}"} # type: ignore + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}"} # type: ignore + @distributed_trace + def begin_delete( + self, resource_group_name: str, server_name: str, database_name: str, link_id: str, **kwargs: Any + ) -> LROPoller[None]: + """Deletes the replication link. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param link_id: Required. + :type link_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: + """ + _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: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + if cont_token is None: + raw_result = self._delete_initial( # type: ignore + resource_group_name=resource_group_name, + server_name=server_name, + database_name=database_name, + link_id=link_id, + api_version=api_version, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements + if cls: + return cls(pipeline_response, None, {}) + + if polling is True: + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling + if cont_token: + return LROPoller.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.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}"} # type: ignore def _failover_initial( - self, - resource_group_name: str, - server_name: str, - database_name: str, - link_id: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, link_id: str, **kwargs: Any ) -> Optional[_models.ReplicationLink]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ReplicationLink]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ReplicationLink]] - - request = build_failover_request_initial( + request = build_failover_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, link_id=link_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._failover_initial.metadata['url'], + template_url=self._failover_initial.metadata["url"], headers=_headers, params=_params, ) @@ -560,10 +519,9 @@ def _failover_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -572,39 +530,30 @@ def _failover_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ReplicationLink', pipeline_response) + deserialized = self._deserialize("ReplicationLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _failover_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/failover"} # type: ignore - + _failover_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/failover"} # type: ignore @distributed_trace def begin_failover( - self, - resource_group_name: str, - server_name: str, - database_name: str, - link_id: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, link_id: str, **kwargs: Any ) -> LROPoller[_models.ReplicationLink]: """Fails over from the current primary server to this server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param link_id: The name of the replication link. + :param link_id: The name of the replication link. Required. :type link_id: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -616,19 +565,16 @@ def begin_failover( :return: An instance of LROPoller that returns either ReplicationLink or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ReplicationLink] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ReplicationLink] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ReplicationLink] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._failover_initial( # type: ignore resource_group_name=resource_group_name, @@ -636,68 +582,56 @@ def begin_failover( database_name=database_name, link_id=link_id, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ReplicationLink', pipeline_response) + deserialized = self._deserialize("ReplicationLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_failover.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/failover"} # type: ignore + begin_failover.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/failover"} # type: ignore def _failover_allow_data_loss_initial( - self, - resource_group_name: str, - server_name: str, - database_name: str, - link_id: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, link_id: str, **kwargs: Any ) -> Optional[_models.ReplicationLink]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ReplicationLink]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ReplicationLink]] - - request = build_failover_allow_data_loss_request_initial( + request = build_failover_allow_data_loss_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, link_id=link_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._failover_allow_data_loss_initial.metadata['url'], + template_url=self._failover_allow_data_loss_initial.metadata["url"], headers=_headers, params=_params, ) @@ -705,10 +639,9 @@ def _failover_allow_data_loss_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -717,39 +650,30 @@ def _failover_allow_data_loss_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ReplicationLink', pipeline_response) + deserialized = self._deserialize("ReplicationLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _failover_allow_data_loss_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/forceFailoverAllowDataLoss"} # type: ignore - + _failover_allow_data_loss_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/forceFailoverAllowDataLoss"} # type: ignore @distributed_trace def begin_failover_allow_data_loss( - self, - resource_group_name: str, - server_name: str, - database_name: str, - link_id: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, link_id: str, **kwargs: Any ) -> LROPoller[_models.ReplicationLink]: """Fails over from the current primary server to this server allowing data loss. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param link_id: The name of the replication link. + :param link_id: The name of the replication link. Required. :type link_id: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -761,19 +685,16 @@ def begin_failover_allow_data_loss( :return: An instance of LROPoller that returns either ReplicationLink or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ReplicationLink] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ReplicationLink] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ReplicationLink] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._failover_allow_data_loss_initial( # type: ignore resource_group_name=resource_group_name, @@ -781,82 +702,70 @@ def begin_failover_allow_data_loss( database_name=database_name, link_id=link_id, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ReplicationLink', pipeline_response) + deserialized = self._deserialize("ReplicationLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_failover_allow_data_loss.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/forceFailoverAllowDataLoss"} # type: ignore + begin_failover_allow_data_loss.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/forceFailoverAllowDataLoss"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.ReplicationLinkListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.ReplicationLink"]: """Gets a list of replication links. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ReplicationLinkListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ReplicationLinkListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ReplicationLink or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ReplicationLink] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ReplicationLinkListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ReplicationLinkListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -864,16 +773,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -889,10 +789,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -902,8 +800,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/replicationLinks"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/replicationLinks"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_restorable_dropped_databases_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_restorable_dropped_databases_operations.py index 45cc1feddc006..d1d054f325bec 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_restorable_dropped_databases_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_restorable_dropped_databases_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,87 +24,80 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/restorableDroppedDatabases") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/restorableDroppedDatabases", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - server_name: str, - restorable_dropped_database_id: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, restorable_dropped_database_id: str, subscription_id: str, **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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "restorableDroppedDatabaseId": _SERIALIZER.url("restorable_dropped_database_id", restorable_dropped_database_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "restorableDroppedDatabaseId": _SERIALIZER.url( + "restorable_dropped_database_id", restorable_dropped_database_id, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class RestorableDroppedDatabasesOperations: """ @@ -121,50 +118,41 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.RestorableDroppedDatabaseListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.RestorableDroppedDatabase"]: """Gets a list of restorable dropped databases. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either RestorableDroppedDatabaseListResult or the result - of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.RestorableDroppedDatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either RestorableDroppedDatabase or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.RestorableDroppedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RestorableDroppedDatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RestorableDroppedDatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -172,16 +160,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -197,10 +176,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -210,56 +187,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/restorableDroppedDatabases"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/restorableDroppedDatabases"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - restorable_dropped_database_id: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, restorable_dropped_database_id: str, **kwargs: Any ) -> _models.RestorableDroppedDatabase: """Gets a restorable dropped database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param restorable_dropped_database_id: + :param restorable_dropped_database_id: Required. :type restorable_dropped_database_id: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: RestorableDroppedDatabase, or the result of cls(response) + :return: RestorableDroppedDatabase or the result of cls(response) :rtype: ~azure.mgmt.sql.models.RestorableDroppedDatabase - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RestorableDroppedDatabase] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RestorableDroppedDatabase] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, restorable_dropped_database_id=restorable_dropped_database_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -267,22 +232,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('RestorableDroppedDatabase', pipeline_response) + deserialized = self._deserialize("RestorableDroppedDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_restorable_dropped_managed_databases_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_restorable_dropped_managed_databases_operations.py index eea98637e0e8d..63e013aea2467 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_restorable_dropped_managed_databases_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_restorable_dropped_managed_databases_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,48 +24,45 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_instance_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -74,33 +75,33 @@ 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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "restorableDroppedDatabaseId": _SERIALIZER.url("restorable_dropped_database_id", restorable_dropped_database_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "restorableDroppedDatabaseId": _SERIALIZER.url( + "restorable_dropped_database_id", restorable_dropped_database_id, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class RestorableDroppedManagedDatabasesOperations: """ @@ -121,50 +122,41 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> Iterable[_models.RestorableDroppedManagedDatabaseListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.RestorableDroppedManagedDatabase"]: """Gets a list of restorable dropped managed databases. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either RestorableDroppedManagedDatabaseListResult or the - result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.RestorableDroppedManagedDatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either RestorableDroppedManagedDatabase or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.RestorableDroppedManagedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RestorableDroppedManagedDatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RestorableDroppedManagedDatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -172,16 +164,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -197,10 +180,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -210,56 +191,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - managed_instance_name: str, - restorable_dropped_database_id: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, restorable_dropped_database_id: str, **kwargs: Any ) -> _models.RestorableDroppedManagedDatabase: """Gets a restorable dropped managed database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param restorable_dropped_database_id: + :param restorable_dropped_database_id: Required. :type restorable_dropped_database_id: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: RestorableDroppedManagedDatabase, or the result of cls(response) + :return: RestorableDroppedManagedDatabase or the result of cls(response) :rtype: ~azure.mgmt.sql.models.RestorableDroppedManagedDatabase - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RestorableDroppedManagedDatabase] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RestorableDroppedManagedDatabase] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, restorable_dropped_database_id=restorable_dropped_database_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -267,22 +236,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('RestorableDroppedManagedDatabase', pipeline_response) + deserialized = self._deserialize("RestorableDroppedManagedDatabase", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_restore_points_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_restore_points_operations.py index 1ac6e8998be89..e750b3bde8010 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_restore_points_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_restore_points_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,97 +26,81 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_database_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_request_initial( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - *, - json: Optional[_models.CreateDatabaseRestorePointDefinition] = None, - content: Any = None, - **kwargs: Any +def build_create_request( + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -126,34 +114,31 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints/{restorePointName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints/{restorePointName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "restorePointName": _SERIALIZER.url("restore_point_name", restore_point_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "restorePointName": _SERIALIZER.url("restore_point_name", restore_point_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_delete_request( @@ -166,28 +151,27 @@ def build_delete_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints/{restorePointName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints/{restorePointName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "restorePointName": _SERIALIZER.url("restore_point_name", restore_point_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "restorePointName": _SERIALIZER.url("restore_point_name", restore_point_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) class RestorePointsOperations: """ @@ -208,53 +192,43 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.RestorePointListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.RestorePoint"]: """Gets a list of database restore points. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either RestorePointListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.RestorePointListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either RestorePoint or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.RestorePoint] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RestorePointListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RestorePointListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -262,17 +236,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -288,10 +252,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -301,35 +263,37 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints"} # type: ignore def _create_initial( self, resource_group_name: str, server_name: str, database_name: str, - parameters: _models.CreateDatabaseRestorePointDefinition, + parameters: Union[_models.CreateDatabaseRestorePointDefinition, IO], **kwargs: Any ) -> Optional[_models.RestorePoint]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.RestorePoint]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.RestorePoint]] - _json = self._serialize.body(parameters, 'CreateDatabaseRestorePointDefinition') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "CreateDatabaseRestorePointDefinition") - request = build_create_request_initial( + request = build_create_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -337,7 +301,8 @@ def _create_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_initial.metadata['url'], + content=_content, + template_url=self._create_initial.metadata["url"], headers=_headers, params=_params, ) @@ -345,10 +310,9 @@ def _create_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -357,42 +321,43 @@ def _create_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('RestorePoint', pipeline_response) + deserialized = self._deserialize("RestorePoint", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('RestorePoint', pipeline_response) + deserialized = self._deserialize("RestorePoint", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints"} # type: ignore + _create_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints"} # type: ignore - - @distributed_trace + @overload def begin_create( self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.CreateDatabaseRestorePointDefinition, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.RestorePoint]: """Creates a restore point for a data warehouse. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: The definition for creating the restore point of this database. + :param parameters: The definition for creating the restore point of this database. Required. :type parameters: ~azure.mgmt.sql.models.CreateDatabaseRestorePointDefinition - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -404,20 +369,94 @@ def begin_create( :return: An instance of LROPoller that returns either RestorePoint or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.RestorePoint] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.RestorePoint]: + """Creates a restore point for a data warehouse. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The definition for creating the restore point of this database. Required. + :type parameters: IO + :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 RestorePoint or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.RestorePoint] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create( + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.CreateDatabaseRestorePointDefinition, IO], + **kwargs: Any + ) -> LROPoller[_models.RestorePoint]: + """Creates a restore point for a data warehouse. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: The definition for creating the restore point of this database. Is either a + model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.CreateDatabaseRestorePointDefinition 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. + :return: An instance of LROPoller that returns either RestorePoint or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.RestorePoint] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.RestorePoint] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.RestorePoint] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_initial( # type: ignore resource_group_name=resource_group_name, @@ -426,80 +465,65 @@ def begin_create( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('RestorePoint', pipeline_response) + deserialized = self._deserialize("RestorePoint", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_create.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints"} # type: ignore + begin_create.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - restore_point_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, restore_point_name: str, **kwargs: Any ) -> _models.RestorePoint: """Gets a restore point. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param restore_point_name: The name of the restore point. + :param restore_point_name: The name of the restore point. Required. :type restore_point_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: RestorePoint, or the result of cls(response) + :return: RestorePoint or the result of cls(response) :rtype: ~azure.mgmt.sql.models.RestorePoint - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.RestorePoint] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.RestorePoint] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -507,7 +531,7 @@ def get( restore_point_name=restore_point_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -515,66 +539,53 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('RestorePoint', pipeline_response) + deserialized = self._deserialize("RestorePoint", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints/{restorePointName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints/{restorePointName}"} # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - restore_point_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, restore_point_name: str, **kwargs: Any ) -> None: """Deletes a restore point. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param restore_point_name: The name of the restore point. + :param restore_point_name: The name of the restore point. Required. :type restore_point_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -582,7 +593,7 @@ def delete( # pylint: disable=inconsistent-return-statements restore_point_name=restore_point_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -590,10 +601,9 @@ def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -603,5 +613,4 @@ def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints/{restorePointName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/restorePoints/{restorePointName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sensitivity_labels_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sensitivity_labels_operations.py index d38c6c36b4bc5..b30aa96e8a971 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sensitivity_labels_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sensitivity_labels_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_current_by_database_request( resource_group_name: str, server_name: str, @@ -41,83 +48,68 @@ def build_list_current_by_database_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/currentSensitivityLabels") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/currentSensitivityLabels", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if skip_token is not None: - _params['$skipToken'] = _SERIALIZER.query("skip_token", skip_token, 'str') + _params["$skipToken"] = _SERIALIZER.query("skip_token", skip_token, "str") if count is not None: - _params['$count'] = _SERIALIZER.query("count", count, 'bool') + _params["$count"] = _SERIALIZER.query("count", count, "bool") if filter is not None: - _params['$filter'] = _SERIALIZER.query("filter", filter, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$filter"] = _SERIALIZER.query("filter", filter, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_update_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - *, - json: Optional[_models.SensitivityLabelUpdateList] = None, - content: Any = None, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/currentSensitivityLabels") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/currentSensitivityLabels", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) def build_list_recommended_by_database_request( @@ -134,39 +126,38 @@ def build_list_recommended_by_database_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/recommendedSensitivityLabels") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/recommendedSensitivityLabels", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if skip_token is not None: - _params['$skipToken'] = _SERIALIZER.query("skip_token", skip_token, 'str') + _params["$skipToken"] = _SERIALIZER.query("skip_token", skip_token, "str") if include_disabled_recommendations is not None: - _params['includeDisabledRecommendations'] = _SERIALIZER.query("include_disabled_recommendations", include_disabled_recommendations, 'bool') + _params["includeDisabledRecommendations"] = _SERIALIZER.query( + "include_disabled_recommendations", include_disabled_recommendations, "bool" + ) if filter is not None: - _params['$filter'] = _SERIALIZER.query("filter", filter, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$filter"] = _SERIALIZER.query("filter", filter, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_enable_recommendation_request( @@ -181,32 +172,30 @@ def build_enable_recommendation_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "recommended") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "recommended") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/enable") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/enable", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "tableName": _SERIALIZER.url("table_name", table_name, 'str'), - "columnName": _SERIALIZER.url("column_name", column_name, 'str'), - "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "tableName": _SERIALIZER.url("table_name", table_name, "str"), + "columnName": _SERIALIZER.url("column_name", column_name, "str"), + "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) def build_disable_recommendation_request( @@ -221,32 +210,30 @@ def build_disable_recommendation_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "recommended") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "recommended") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/disable") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/disable", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "tableName": _SERIALIZER.url("table_name", table_name, 'str'), - "columnName": _SERIALIZER.url("column_name", column_name, 'str'), - "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "tableName": _SERIALIZER.url("table_name", table_name, "str"), + "columnName": _SERIALIZER.url("column_name", column_name, "str"), + "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) def build_get_request( @@ -263,37 +250,34 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "tableName": _SERIALIZER.url("table_name", table_name, 'str'), - "columnName": _SERIALIZER.url("column_name", column_name, 'str'), - "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "tableName": _SERIALIZER.url("table_name", table_name, "str"), + "columnName": _SERIALIZER.url("column_name", column_name, "str"), + "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( @@ -304,51 +288,43 @@ def build_create_or_update_request( table_name: str, column_name: str, subscription_id: str, - *, - json: Optional[_models.SensitivityLabel] = None, - content: Any = None, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "current") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "current") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "tableName": _SERIALIZER.url("table_name", table_name, 'str'), - "columnName": _SERIALIZER.url("column_name", column_name, 'str'), - "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "tableName": _SERIALIZER.url("table_name", table_name, "str"), + "columnName": _SERIALIZER.url("column_name", column_name, "str"), + "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_delete_request( @@ -363,32 +339,31 @@ def build_delete_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "current") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "current") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "schemaName": _SERIALIZER.url("schema_name", schema_name, 'str'), - "tableName": _SERIALIZER.url("table_name", table_name, 'str'), - "columnName": _SERIALIZER.url("column_name", column_name, 'str'), - "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "schemaName": _SERIALIZER.url("schema_name", schema_name, "str"), + "tableName": _SERIALIZER.url("table_name", table_name, "str"), + "columnName": _SERIALIZER.url("column_name", column_name, "str"), + "sensitivityLabelSource": _SERIALIZER.url("sensitivity_label_source", sensitivity_label_source, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) class SensitivityLabelsOperations: """ @@ -409,7 +384,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_current_by_database( self, @@ -420,55 +394,50 @@ def list_current_by_database( count: Optional[bool] = None, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable[_models.SensitivityLabelListResult]: + ) -> Iterable["_models.SensitivityLabel"]: """Gets the sensitivity labels of a given database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param skip_token: Default value is None. + :param skip_token: Default value is None. :type skip_token: str - :param count: Default value is None. + :param count: Default value is None. :type count: bool :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SensitivityLabelListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SensitivityLabelListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SensitivityLabel or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SensitivityLabel] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SensitivityLabelListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SensitivityLabelListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_current_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, skip_token=skip_token, count=count, filter=filter, - template_url=self.list_current_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_current_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -476,20 +445,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_current_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - skip_token=skip_token, - count=count, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -505,10 +461,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -518,53 +472,117 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_current_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/currentSensitivityLabels"} # type: ignore + list_current_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/currentSensitivityLabels"} # type: ignore - @distributed_trace + @overload def update( # pylint: disable=inconsistent-return-statements self, resource_group_name: str, server_name: str, database_name: str, parameters: _models.SensitivityLabelUpdateList, + *, + content_type: str = "application/json", **kwargs: Any ) -> None: """Update sensitivity labels of a given database using an operations batch. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.SensitivityLabelUpdateList - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + def update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> None: + """Update sensitivity labels of a given database using an operations batch. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Required. + :type parameters: IO + :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: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def update( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + server_name: str, + database_name: str, + parameters: Union[_models.SensitivityLabelUpdateList, IO], + **kwargs: Any + ) -> None: + """Update sensitivity labels of a given database using an operations batch. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.SensitivityLabelUpdateList 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 + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'SensitivityLabelUpdateList') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SensitivityLabelUpdateList") request = build_update_request( resource_group_name=resource_group_name, @@ -574,7 +592,8 @@ def update( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -582,10 +601,9 @@ def update( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -595,8 +613,7 @@ def update( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/currentSensitivityLabels"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/currentSensitivityLabels"} # type: ignore @distributed_trace def list_recommended_by_database( @@ -608,17 +625,17 @@ def list_recommended_by_database( include_disabled_recommendations: Optional[bool] = None, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable[_models.SensitivityLabelListResult]: + ) -> Iterable["_models.SensitivityLabel"]: """Gets the sensitivity labels of a given database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param skip_token: Default value is None. + :param skip_token: Default value is None. :type skip_token: str :param include_disabled_recommendations: Specifies whether to include disabled recommendations or not. Default value is None. @@ -626,38 +643,33 @@ def list_recommended_by_database( :param filter: An OData filter expression that filters elements in the collection. Default value is None. :type filter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SensitivityLabelListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SensitivityLabelListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SensitivityLabel or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SensitivityLabel] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SensitivityLabelListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SensitivityLabelListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_recommended_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, - api_version=api_version, skip_token=skip_token, include_disabled_recommendations=include_disabled_recommendations, filter=filter, - template_url=self.list_recommended_by_database.metadata['url'], + api_version=api_version, + template_url=self.list_recommended_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -665,20 +677,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_recommended_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - skip_token=skip_token, - include_disabled_recommendations=include_disabled_recommendations, - filter=filter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -694,10 +693,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -707,11 +704,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_recommended_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/recommendedSensitivityLabels"} # type: ignore + list_recommended_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/recommendedSensitivityLabels"} # type: ignore @distributed_trace def enable_recommendation( # pylint: disable=inconsistent-return-statements @@ -728,42 +723,36 @@ def enable_recommendation( # pylint: disable=inconsistent-return-statements on all columns). :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :keyword sensitivity_label_source: Default value is "recommended". Note that overriding this + :keyword sensitivity_label_source: Default value is "recommended". Note that overriding this default value may result in unsupported behavior. :paramtype sensitivity_label_source: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "recommended") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "recommended") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_enable_recommendation_request( resource_group_name=resource_group_name, server_name=server_name, @@ -774,7 +763,7 @@ def enable_recommendation( # pylint: disable=inconsistent-return-statements subscription_id=self._config.subscription_id, sensitivity_label_source=sensitivity_label_source, api_version=api_version, - template_url=self.enable_recommendation.metadata['url'], + template_url=self.enable_recommendation.metadata["url"], headers=_headers, params=_params, ) @@ -782,10 +771,9 @@ def enable_recommendation( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -795,8 +783,7 @@ def enable_recommendation( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - enable_recommendation.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/enable"} # type: ignore - + enable_recommendation.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/enable"} # type: ignore @distributed_trace def disable_recommendation( # pylint: disable=inconsistent-return-statements @@ -812,42 +799,36 @@ def disable_recommendation( # pylint: disable=inconsistent-return-statements """Disables sensitivity recommendations on a given column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :keyword sensitivity_label_source: Default value is "recommended". Note that overriding this + :keyword sensitivity_label_source: Default value is "recommended". Note that overriding this default value may result in unsupported behavior. :paramtype sensitivity_label_source: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "recommended") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "recommended") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_disable_recommendation_request( resource_group_name=resource_group_name, server_name=server_name, @@ -858,7 +839,7 @@ def disable_recommendation( # pylint: disable=inconsistent-return-statements subscription_id=self._config.subscription_id, sensitivity_label_source=sensitivity_label_source, api_version=api_version, - template_url=self.disable_recommendation.metadata['url'], + template_url=self.disable_recommendation.metadata["url"], headers=_headers, params=_params, ) @@ -866,10 +847,9 @@ def disable_recommendation( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -879,8 +859,7 @@ def disable_recommendation( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - disable_recommendation.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/disable"} # type: ignore - + disable_recommendation.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}/disable"} # type: ignore @distributed_trace def get( @@ -897,40 +876,35 @@ def get( """Gets the sensitivity label of a given column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :param sensitivity_label_source: The source of the sensitivity label. + :param sensitivity_label_source: The source of the sensitivity label. Known values are: + "current" and "recommended". Required. :type sensitivity_label_source: str or ~azure.mgmt.sql.models.SensitivityLabelSource - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SensitivityLabel, or the result of cls(response) + :return: SensitivityLabel or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SensitivityLabel - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SensitivityLabel] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SensitivityLabel] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -941,7 +915,7 @@ def get( sensitivity_label_source=sensitivity_label_source, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -949,27 +923,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SensitivityLabel', pipeline_response) + deserialized = self._deserialize("SensitivityLabel", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, @@ -979,50 +951,141 @@ def create_or_update( table_name: str, column_name: str, parameters: _models.SensitivityLabel, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.SensitivityLabel: """Creates or updates the sensitivity label of a given column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str - :param parameters: The column sensitivity label resource. + :param parameters: The column sensitivity label resource. Required. :type parameters: ~azure.mgmt.sql.models.SensitivityLabel + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str :keyword sensitivity_label_source: The source of the sensitivity label. Default value is "current". Note that overriding this default value may result in unsupported behavior. :paramtype sensitivity_label_source: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SensitivityLabel, or the result of cls(response) + :return: SensitivityLabel or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SensitivityLabel - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + schema_name: str, + table_name: str, + column_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.SensitivityLabel: + """Creates or updates the sensitivity label of a given column. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param schema_name: The name of the schema. Required. + :type schema_name: str + :param table_name: The name of the table. Required. + :type table_name: str + :param column_name: The name of the column. Required. + :type column_name: str + :param parameters: The column sensitivity label resource. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword sensitivity_label_source: The source of the sensitivity label. Default value is + "current". Note that overriding this default value may result in unsupported behavior. + :paramtype sensitivity_label_source: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SensitivityLabel or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.SensitivityLabel + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + schema_name: str, + table_name: str, + column_name: str, + parameters: Union[_models.SensitivityLabel, IO], + **kwargs: Any + ) -> _models.SensitivityLabel: + """Creates or updates the sensitivity label of a given column. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param schema_name: The name of the schema. Required. + :type schema_name: str + :param table_name: The name of the table. Required. + :type table_name: str + :param column_name: The name of the column. Required. + :type column_name: str + :param parameters: The column sensitivity label resource. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.SensitivityLabel or IO + :keyword sensitivity_label_source: The source of the sensitivity label. Default value is + "current". Note that overriding this default value may result in unsupported behavior. + :paramtype sensitivity_label_source: str + :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 + :return: SensitivityLabel or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.SensitivityLabel + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "current") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.SensitivityLabel] + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "current") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.SensitivityLabel] - _json = self._serialize.body(parameters, 'SensitivityLabel') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SensitivityLabel") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -1036,7 +1099,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -1044,10 +1108,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -1055,18 +1118,17 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('SensitivityLabel', pipeline_response) + deserialized = self._deserialize("SensitivityLabel", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('SensitivityLabel', pipeline_response) + deserialized = self._deserialize("SensitivityLabel", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -1082,42 +1144,36 @@ def delete( # pylint: disable=inconsistent-return-statements """Deletes the sensitivity label of a given column. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param schema_name: The name of the schema. + :param schema_name: The name of the schema. Required. :type schema_name: str - :param table_name: The name of the table. + :param table_name: The name of the table. Required. :type table_name: str - :param column_name: The name of the column. + :param column_name: The name of the column. Required. :type column_name: str :keyword sensitivity_label_source: The source of the sensitivity label. Default value is "current". Note that overriding this default value may result in unsupported behavior. :paramtype sensitivity_label_source: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - sensitivity_label_source = kwargs.pop('sensitivity_label_source', "current") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + sensitivity_label_source = kwargs.pop("sensitivity_label_source", "current") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, @@ -1128,7 +1184,7 @@ def delete( # pylint: disable=inconsistent-return-statements subscription_id=self._config.subscription_id, sensitivity_label_source=sensitivity_label_source, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -1136,10 +1192,9 @@ def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -1149,5 +1204,4 @@ def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/schemas/{schemaName}/tables/{tableName}/columns/{columnName}/sensitivityLabels/{sensitivityLabelSource}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_advanced_threat_protection_settings_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_advanced_threat_protection_settings_operations.py index bd2b6dbd0a341..75edba313554f 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_advanced_threat_protection_settings_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_advanced_threat_protection_settings_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,48 +26,45 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( @@ -76,80 +77,74 @@ 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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "advancedThreatProtectionName": _SERIALIZER.url("advanced_threat_protection_name", advanced_threat_protection_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "advancedThreatProtectionName": _SERIALIZER.url( + "advanced_threat_protection_name", advanced_threat_protection_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, server_name: str, advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], subscription_id: str, - *, - json: Optional[_models.ServerAdvancedThreatProtection] = None, - content: Any = None, **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', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "advancedThreatProtectionName": _SERIALIZER.url("advanced_threat_protection_name", advanced_threat_protection_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "advancedThreatProtectionName": _SERIALIZER.url( + "advanced_threat_protection_name", advanced_threat_protection_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + class ServerAdvancedThreatProtectionSettingsOperations: """ @@ -170,50 +165,41 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.LogicalServerAdvancedThreatProtectionListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.ServerAdvancedThreatProtection"]: """Get a list of the server's Advanced Threat Protection states. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LogicalServerAdvancedThreatProtectionListResult or - the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LogicalServerAdvancedThreatProtectionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServerAdvancedThreatProtection or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LogicalServerAdvancedThreatProtectionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LogicalServerAdvancedThreatProtectionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -221,16 +207,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -246,10 +223,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -259,11 +234,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings"} # type: ignore @distributed_trace def get( @@ -276,40 +249,35 @@ def get( """Get a server's Advanced Threat Protection state. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. :type advanced_threat_protection_name: str or ~azure.mgmt.sql.models.AdvancedThreatProtectionName - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerAdvancedThreatProtection, or the result of cls(response) + :return: ServerAdvancedThreatProtection or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerAdvancedThreatProtection - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerAdvancedThreatProtection] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerAdvancedThreatProtection] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, advanced_threat_protection_name=advanced_threat_protection_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -317,49 +285,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerAdvancedThreatProtection', pipeline_response) + deserialized = self._deserialize("ServerAdvancedThreatProtection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], - parameters: _models.ServerAdvancedThreatProtection, + parameters: Union[_models.ServerAdvancedThreatProtection, IO], **kwargs: Any ) -> Optional[_models.ServerAdvancedThreatProtection]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerAdvancedThreatProtection]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerAdvancedThreatProtection]] - _json = self._serialize.body(parameters, 'ServerAdvancedThreatProtection') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerAdvancedThreatProtection") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, advanced_threat_protection_name=advanced_threat_protection_name, @@ -367,7 +337,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -375,10 +346,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -387,40 +357,42 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerAdvancedThreatProtection', pipeline_response) + deserialized = self._deserialize("ServerAdvancedThreatProtection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], parameters: _models.ServerAdvancedThreatProtection, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ServerAdvancedThreatProtection]: """Creates or updates an Advanced Threat Protection state. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. :type advanced_threat_protection_name: str or ~azure.mgmt.sql.models.AdvancedThreatProtectionName - :param parameters: The server Advanced Threat Protection state. + :param parameters: The server Advanced Threat Protection state. Required. :type parameters: ~azure.mgmt.sql.models.ServerAdvancedThreatProtection - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -432,20 +404,98 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ServerAdvancedThreatProtection or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerAdvancedThreatProtection] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ServerAdvancedThreatProtection]: + """Creates or updates an Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The server Advanced Threat Protection state. Required. + :type parameters: IO + :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 ServerAdvancedThreatProtection or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + advanced_threat_protection_name: Union[str, "_models.AdvancedThreatProtectionName"], + parameters: Union[_models.ServerAdvancedThreatProtection, IO], + **kwargs: Any + ) -> LROPoller[_models.ServerAdvancedThreatProtection]: + """Creates or updates an Advanced Threat Protection state. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param advanced_threat_protection_name: The name of the Advanced Threat Protection state. + "Default" Required. + :type advanced_threat_protection_name: str or + ~azure.mgmt.sql.models.AdvancedThreatProtectionName + :param parameters: The server Advanced Threat Protection state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerAdvancedThreatProtection 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. + :return: An instance of LROPoller that returns either ServerAdvancedThreatProtection or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerAdvancedThreatProtection] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerAdvancedThreatProtection] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerAdvancedThreatProtection] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -454,36 +504,32 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerAdvancedThreatProtection', pipeline_response) + deserialized = self._deserialize("ServerAdvancedThreatProtection", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advancedThreatProtectionSettings/{advancedThreatProtectionName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_advisors_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_advisors_operations.py index e86a5c12fc474..f82c066b0bc8d 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_advisors_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_advisors_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, List, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, List, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse from azure.core.rest import HttpRequest @@ -19,138 +23,115 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - *, - expand: Optional[str] = None, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, *, expand: Optional[str] = None, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if expand is not None: - _params['$expand'] = _SERIALIZER.query("expand", expand, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$expand"] = _SERIALIZER.query("expand", expand, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - server_name: str, - advisor_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, advisor_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors/{advisorName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors/{advisorName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "advisorName": _SERIALIZER.url("advisor_name", advisor_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "advisorName": _SERIALIZER.url("advisor_name", advisor_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_update_request( - resource_group_name: str, - server_name: str, - advisor_name: str, - subscription_id: str, - *, - json: Optional[_models.Advisor] = None, - content: Any = None, - **kwargs: Any + resource_group_name: str, server_name: str, advisor_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors/{advisorName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors/{advisorName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "advisorName": _SERIALIZER.url("advisor_name", advisor_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "advisorName": _SERIALIZER.url("advisor_name", advisor_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) + class ServerAdvisorsOperations: """ @@ -171,51 +152,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - expand: Optional[str] = None, - **kwargs: Any + self, resource_group_name: str, server_name: str, expand: Optional[str] = None, **kwargs: Any ) -> List[_models.Advisor]: """Gets a list of server advisors. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: list of Advisor, or the result of cls(response) + :return: list of Advisor or the result of cls(response) :rtype: list[~azure.mgmt.sql.models.Advisor] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[List[_models.Advisor]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[List[_models.Advisor]] - request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.list_by_server.metadata['url'], + api_version=api_version, + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -223,70 +193,56 @@ def list_by_server( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('[Advisor]', pipeline_response) + deserialized = self._deserialize("[Advisor]", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors"} # type: ignore - + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors"} # type: ignore @distributed_trace - def get( - self, - resource_group_name: str, - server_name: str, - advisor_name: str, - **kwargs: Any - ) -> _models.Advisor: + def get(self, resource_group_name: str, server_name: str, advisor_name: str, **kwargs: Any) -> _models.Advisor: """Gets a server advisor. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param advisor_name: The name of the Server Advisor. + :param advisor_name: The name of the Server Advisor. Required. :type advisor_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Advisor, or the result of cls(response) + :return: Advisor or the result of cls(response) :rtype: ~azure.mgmt.sql.models.Advisor - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.Advisor] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.Advisor] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, advisor_name=advisor_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -294,67 +250,132 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('Advisor', pipeline_response) + deserialized = self._deserialize("Advisor", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors/{advisorName}"} # type: ignore + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors/{advisorName}"} # type: ignore - - @distributed_trace + @overload def update( self, resource_group_name: str, server_name: str, advisor_name: str, parameters: _models.Advisor, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.Advisor: """Updates a server advisor. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param advisor_name: The name of the Server Advisor. + :param advisor_name: The name of the Server Advisor. Required. :type advisor_name: str - :param parameters: The requested advisor resource state. + :param parameters: The requested advisor resource state. Required. :type parameters: ~azure.mgmt.sql.models.Advisor - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: Advisor, or the result of cls(response) + :return: Advisor or the result of cls(response) :rtype: ~azure.mgmt.sql.models.Advisor - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + def update( + self, + resource_group_name: str, + server_name: str, + advisor_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.Advisor: + """Updates a server advisor. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param advisor_name: The name of the Server Advisor. Required. + :type advisor_name: str + :param parameters: The requested advisor resource state. Required. + :type parameters: IO + :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: Advisor or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.Advisor + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def update( + self, + resource_group_name: str, + server_name: str, + advisor_name: str, + parameters: Union[_models.Advisor, IO], + **kwargs: Any + ) -> _models.Advisor: + """Updates a server advisor. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param advisor_name: The name of the Server Advisor. Required. + :type advisor_name: str + :param parameters: The requested advisor resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.Advisor 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 + :return: Advisor or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.Advisor + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.Advisor] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.Advisor] - _json = self._serialize.body(parameters, 'Advisor') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "Advisor") request = build_update_request( resource_group_name=resource_group_name, @@ -364,7 +385,8 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -372,22 +394,20 @@ def update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('Advisor', pipeline_response) + deserialized = self._deserialize("Advisor", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors/{advisorName}"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/advisors/{advisorName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_automatic_tuning_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_automatic_tuning_operations.py index e80be462f907f..c564665ffeb95 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_automatic_tuning_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_automatic_tuning_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse from azure.core.rest import HttpRequest @@ -19,93 +23,78 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False -def build_get_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any -) -> HttpRequest: + +def build_get_request(resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/automaticTuning/current") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/automaticTuning/current", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_update_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - *, - json: Optional[_models.ServerAutomaticTuning] = None, - content: Any = None, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/automaticTuning/current") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/automaticTuning/current", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) + class ServerAutomaticTuningOperations: """ @@ -126,47 +115,35 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace - def get( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> _models.ServerAutomaticTuning: + def get(self, resource_group_name: str, server_name: str, **kwargs: Any) -> _models.ServerAutomaticTuning: """Retrieves server automatic tuning options. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerAutomaticTuning, or the result of cls(response) + :return: ServerAutomaticTuning or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerAutomaticTuning - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerAutomaticTuning] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerAutomaticTuning] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -174,64 +151,123 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerAutomaticTuning', pipeline_response) + deserialized = self._deserialize("ServerAutomaticTuning", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/automaticTuning/current"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/automaticTuning/current"} # type: ignore - @distributed_trace + @overload def update( self, resource_group_name: str, server_name: str, parameters: _models.ServerAutomaticTuning, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.ServerAutomaticTuning: """Update automatic tuning options on server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param parameters: The requested automatic tuning resource state. + :param parameters: The requested automatic tuning resource state. Required. :type parameters: ~azure.mgmt.sql.models.ServerAutomaticTuning - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: ServerAutomaticTuning, or the result of cls(response) + :return: ServerAutomaticTuning or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerAutomaticTuning - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + def update( + self, + resource_group_name: str, + server_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.ServerAutomaticTuning: + """Update automatic tuning options on server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The requested automatic tuning resource state. Required. + :type parameters: IO + :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: ServerAutomaticTuning or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ServerAutomaticTuning + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def update( + self, + resource_group_name: str, + server_name: str, + parameters: Union[_models.ServerAutomaticTuning, IO], + **kwargs: Any + ) -> _models.ServerAutomaticTuning: + """Update automatic tuning options on server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The requested automatic tuning resource state. Is either a model type or a + IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerAutomaticTuning 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 + :return: ServerAutomaticTuning or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ServerAutomaticTuning + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerAutomaticTuning] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerAutomaticTuning] - _json = self._serialize.body(parameters, 'ServerAutomaticTuning') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerAutomaticTuning") request = build_update_request( resource_group_name=resource_group_name, @@ -240,7 +276,8 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata['url'], + content=_content, + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -248,22 +285,20 @@ def update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerAutomaticTuning', pipeline_response) + deserialized = self._deserialize("ServerAutomaticTuning", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/automaticTuning/current"} # type: ignore - + update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/automaticTuning/current"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_azure_ad_administrators_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_azure_ad_administrators_operations.py index 16dfafb4aed28..4965ea9d9fbec 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_azure_ad_administrators_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_azure_ad_administrators_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -39,83 +46,72 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "administratorName": _SERIALIZER.url("administrator_name", administrator_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "administratorName": _SERIALIZER.url("administrator_name", administrator_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, server_name: str, administrator_name: Union[str, "_models.AdministratorName"], subscription_id: str, - *, - json: Optional[_models.ServerAzureADAdministrator] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "administratorName": _SERIALIZER.url("administrator_name", administrator_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "administratorName": _SERIALIZER.url("administrator_name", administrator_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_request_initial( +def build_delete_request( resource_group_name: str, server_name: str, administrator_name: Union[str, "_models.AdministratorName"], @@ -124,64 +120,57 @@ def build_delete_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "administratorName": _SERIALIZER.url("administrator_name", administrator_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "administratorName": _SERIALIZER.url("administrator_name", administrator_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ServerAzureADAdministratorsOperations: """ @@ -202,7 +191,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -214,39 +202,34 @@ def get( """Gets a Azure Active Directory administrator. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param administrator_name: The name of server active directory administrator. + :param administrator_name: The name of server active directory administrator. "ActiveDirectory" + Required. :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerAzureADAdministrator, or the result of cls(response) + :return: ServerAzureADAdministrator or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerAzureADAdministrator - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerAzureADAdministrator] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerAzureADAdministrator] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, administrator_name=administrator_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -254,49 +237,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerAzureADAdministrator', pipeline_response) + deserialized = self._deserialize("ServerAzureADAdministrator", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, administrator_name: Union[str, "_models.AdministratorName"], - parameters: _models.ServerAzureADAdministrator, + parameters: Union[_models.ServerAzureADAdministrator, IO], **kwargs: Any ) -> Optional[_models.ServerAzureADAdministrator]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerAzureADAdministrator]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerAzureADAdministrator]] - _json = self._serialize.body(parameters, 'ServerAzureADAdministrator') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerAzureADAdministrator") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, administrator_name=administrator_name, @@ -304,7 +289,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -312,10 +298,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -324,42 +309,123 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerAzureADAdministrator', pipeline_response) + deserialized = self._deserialize("ServerAzureADAdministrator", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ServerAzureADAdministrator', pipeline_response) + deserialized = self._deserialize("ServerAzureADAdministrator", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, administrator_name: Union[str, "_models.AdministratorName"], parameters: _models.ServerAzureADAdministrator, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ServerAzureADAdministrator]: """Creates or updates an existing Azure Active Directory administrator. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param administrator_name: The name of server active directory administrator. + :param administrator_name: The name of server active directory administrator. "ActiveDirectory" + Required. :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName - :param parameters: The requested Azure Active Directory administrator Resource state. + :param parameters: The requested Azure Active Directory administrator Resource state. Required. :type parameters: ~azure.mgmt.sql.models.ServerAzureADAdministrator - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ServerAzureADAdministrator or the result + of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerAzureADAdministrator] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + administrator_name: Union[str, "_models.AdministratorName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ServerAzureADAdministrator]: + """Creates or updates an existing Azure Active Directory administrator. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param administrator_name: The name of server active directory administrator. "ActiveDirectory" + Required. + :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName + :param parameters: The requested Azure Active Directory administrator Resource state. Required. + :type parameters: IO + :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 ServerAzureADAdministrator or the result + of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerAzureADAdministrator] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + administrator_name: Union[str, "_models.AdministratorName"], + parameters: Union[_models.ServerAzureADAdministrator, IO], + **kwargs: Any + ) -> LROPoller[_models.ServerAzureADAdministrator]: + """Creates or updates an existing Azure Active Directory administrator. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param administrator_name: The name of server active directory administrator. "ActiveDirectory" + Required. + :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName + :param parameters: The requested Azure Active Directory administrator Resource state. Is either + a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerAzureADAdministrator 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 @@ -371,20 +437,17 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ServerAzureADAdministrator or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerAzureADAdministrator] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerAzureADAdministrator] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerAzureADAdministrator] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -393,39 +456,35 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerAzureADAdministrator', pipeline_response) + deserialized = self._deserialize("ServerAzureADAdministrator", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements self, @@ -434,25 +493,22 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements administrator_name: Union[str, "_models.AdministratorName"], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, administrator_name=administrator_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -460,10 +516,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -473,11 +528,10 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements + def begin_delete( self, resource_group_name: str, server_name: str, @@ -487,15 +541,13 @@ def begin_delete( # pylint: disable=inconsistent-return-statements """Deletes the Azure Active Directory administrator with the given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param administrator_name: The name of server active directory administrator. + :param administrator_name: The name of server active directory administrator. "ActiveDirectory" + Required. :type administrator_name: str or ~azure.mgmt.sql.models.AdministratorName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -506,99 +558,85 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, administrator_name=administrator_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators/{administratorName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.AdministratorListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.ServerAzureADAdministrator"]: """Gets a list of Azure Active Directory administrators in a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either AdministratorListResult or the result of + :return: An iterator like instance of either ServerAzureADAdministrator or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.AdministratorListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerAzureADAdministrator] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.AdministratorListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.AdministratorListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -606,16 +644,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -631,10 +660,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -644,8 +671,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/administrators"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_azure_ad_only_authentications_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_azure_ad_only_authentications_operations.py index 9aa308523aa11..97235b9a4bbce 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_azure_ad_only_authentications_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_azure_ad_only_authentications_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -39,83 +46,72 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "authenticationName": _SERIALIZER.url("authentication_name", authentication_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "authenticationName": _SERIALIZER.url("authentication_name", authentication_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, server_name: str, authentication_name: Union[str, "_models.AuthenticationName"], subscription_id: str, - *, - json: Optional[_models.ServerAzureADOnlyAuthentication] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "authenticationName": _SERIALIZER.url("authentication_name", authentication_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "authenticationName": _SERIALIZER.url("authentication_name", authentication_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_request_initial( +def build_delete_request( resource_group_name: str, server_name: str, authentication_name: Union[str, "_models.AuthenticationName"], @@ -124,64 +120,57 @@ def build_delete_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "authenticationName": _SERIALIZER.url("authentication_name", authentication_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "authenticationName": _SERIALIZER.url("authentication_name", authentication_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ServerAzureADOnlyAuthenticationsOperations: """ @@ -202,7 +191,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -214,39 +202,34 @@ def get( """Gets a specific Azure Active Directory only authentication property. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerAzureADOnlyAuthentication, or the result of cls(response) + :return: ServerAzureADOnlyAuthentication or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerAzureADOnlyAuthentication - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerAzureADOnlyAuthentication] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerAzureADOnlyAuthentication] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, authentication_name=authentication_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -254,49 +237,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerAzureADOnlyAuthentication', pipeline_response) + deserialized = self._deserialize("ServerAzureADOnlyAuthentication", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, authentication_name: Union[str, "_models.AuthenticationName"], - parameters: _models.ServerAzureADOnlyAuthentication, + parameters: Union[_models.ServerAzureADOnlyAuthentication, IO], **kwargs: Any ) -> Optional[_models.ServerAzureADOnlyAuthentication]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerAzureADOnlyAuthentication]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerAzureADOnlyAuthentication]] - _json = self._serialize.body(parameters, 'ServerAzureADOnlyAuthentication') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerAzureADOnlyAuthentication") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, authentication_name=authentication_name, @@ -304,7 +289,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -312,10 +298,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -324,44 +309,128 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerAzureADOnlyAuthentication', pipeline_response) + deserialized = self._deserialize("ServerAzureADOnlyAuthentication", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ServerAzureADOnlyAuthentication', pipeline_response) + deserialized = self._deserialize("ServerAzureADOnlyAuthentication", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, authentication_name: Union[str, "_models.AuthenticationName"], parameters: _models.ServerAzureADOnlyAuthentication, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ServerAzureADOnlyAuthentication]: """Sets Server Active Directory only authentication property or updates an existing server Active Directory only authentication property. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName :param parameters: The required parameters for creating or updating an Active Directory only - authentication property. + authentication property. Required. :type parameters: ~azure.mgmt.sql.models.ServerAzureADOnlyAuthentication - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ServerAzureADOnlyAuthentication or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerAzureADOnlyAuthentication] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + authentication_name: Union[str, "_models.AuthenticationName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ServerAzureADOnlyAuthentication]: + """Sets Server Active Directory only authentication property or updates an existing server Active + Directory only authentication property. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. + :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName + :param parameters: The required parameters for creating or updating an Active Directory only + authentication property. Required. + :type parameters: IO + :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 ServerAzureADOnlyAuthentication or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerAzureADOnlyAuthentication] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + authentication_name: Union[str, "_models.AuthenticationName"], + parameters: Union[_models.ServerAzureADOnlyAuthentication, IO], + **kwargs: Any + ) -> LROPoller[_models.ServerAzureADOnlyAuthentication]: + """Sets Server Active Directory only authentication property or updates an existing server Active + Directory only authentication property. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. + :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName + :param parameters: The required parameters for creating or updating an Active Directory only + authentication property. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerAzureADOnlyAuthentication 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 @@ -373,20 +442,17 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ServerAzureADOnlyAuthentication or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerAzureADOnlyAuthentication] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerAzureADOnlyAuthentication] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerAzureADOnlyAuthentication] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -395,39 +461,35 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerAzureADOnlyAuthentication', pipeline_response) + deserialized = self._deserialize("ServerAzureADOnlyAuthentication", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements self, @@ -436,25 +498,22 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements authentication_name: Union[str, "_models.AuthenticationName"], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, authentication_name=authentication_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -462,10 +521,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -475,11 +533,10 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements + def begin_delete( self, resource_group_name: str, server_name: str, @@ -489,15 +546,13 @@ def begin_delete( # pylint: disable=inconsistent-return-statements """Deletes an existing server Active Directory only authentication property. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param authentication_name: The name of server azure active directory only authentication. + "Default" Required. :type authentication_name: str or ~azure.mgmt.sql.models.AuthenticationName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -508,99 +563,85 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, authentication_name=authentication_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications/{authenticationName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.AzureADOnlyAuthListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.ServerAzureADOnlyAuthentication"]: """Gets a list of server Azure Active Directory only authentications. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either AzureADOnlyAuthListResult or the result of + :return: An iterator like instance of either ServerAzureADOnlyAuthentication or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.AzureADOnlyAuthListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerAzureADOnlyAuthentication] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.AzureADOnlyAuthListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.AzureADOnlyAuthListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -608,16 +649,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -633,10 +665,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -646,8 +676,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/azureADOnlyAuthentications"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_blob_auditing_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_blob_auditing_policies_operations.py index 30a607eec154c..08fd299fee8fe 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_blob_auditing_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_blob_auditing_policies_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,134 +26,113 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_get_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any -) -> HttpRequest: + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_get_request(resource_group_name: str, server_name: str, subscription_id: str, **kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "blobAuditingPolicyName": _SERIALIZER.url("blob_auditing_policy_name", blob_auditing_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "blobAuditingPolicyName": _SERIALIZER.url("blob_auditing_policy_name", blob_auditing_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - resource_group_name: str, - server_name: str, - subscription_id: str, - *, - json: Optional[_models.ServerBlobAuditingPolicy] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, server_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "blobAuditingPolicyName": _SERIALIZER.url("blob_auditing_policy_name", blob_auditing_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "blobAuditingPolicyName": _SERIALIZER.url("blob_auditing_policy_name", blob_auditing_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + class ServerBlobAuditingPoliciesOperations: """ @@ -170,49 +153,41 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.ServerBlobAuditingPolicyListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.ServerBlobAuditingPolicy"]: """Lists auditing settings of a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerBlobAuditingPolicyListResult or the result - of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerBlobAuditingPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServerBlobAuditingPolicy or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerBlobAuditingPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerBlobAuditingPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerBlobAuditingPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -220,16 +195,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -245,10 +211,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -258,57 +222,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings"} # type: ignore @distributed_trace - def get( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> _models.ServerBlobAuditingPolicy: + def get(self, resource_group_name: str, server_name: str, **kwargs: Any) -> _models.ServerBlobAuditingPolicy: """Gets a server's blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is "default". Note that overriding this default value may result in unsupported behavior. :paramtype blob_auditing_policy_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerBlobAuditingPolicy, or the result of cls(response) + :return: ServerBlobAuditingPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerBlobAuditingPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerBlobAuditingPolicy] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerBlobAuditingPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, blob_auditing_policy_name=blob_auditing_policy_name, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -316,49 +267,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ServerBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, - parameters: _models.ServerBlobAuditingPolicy, + parameters: Union[_models.ServerBlobAuditingPolicy, IO], **kwargs: Any ) -> Optional[_models.ServerBlobAuditingPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerBlobAuditingPolicy]] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerBlobAuditingPolicy]] - _json = self._serialize.body(parameters, 'ServerBlobAuditingPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerBlobAuditingPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, @@ -366,7 +319,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -374,10 +328,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -386,39 +339,40 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ServerBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, parameters: _models.ServerBlobAuditingPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ServerBlobAuditingPolicy]: """Creates or updates a server's blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param parameters: Properties of blob auditing policy. + :param parameters: Properties of blob auditing policy. Required. :type parameters: ~azure.mgmt.sql.models.ServerBlobAuditingPolicy + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is "default". Note that overriding this default value may result in unsupported behavior. :paramtype blob_auditing_policy_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -430,21 +384,95 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ServerBlobAuditingPolicy or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerBlobAuditingPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ServerBlobAuditingPolicy]: + """Creates or updates a server's blob auditing policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: Properties of blob auditing policy. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is + "default". Note that overriding this default value may result in unsupported behavior. + :paramtype blob_auditing_policy_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 ServerBlobAuditingPolicy or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerBlobAuditingPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + parameters: Union[_models.ServerBlobAuditingPolicy, IO], + **kwargs: Any + ) -> LROPoller[_models.ServerBlobAuditingPolicy]: + """Creates or updates a server's blob auditing policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: Properties of blob auditing policy. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ServerBlobAuditingPolicy or IO + :keyword blob_auditing_policy_name: The name of the blob auditing policy. Default value is + "default". Note that overriding this default value may result in unsupported behavior. + :paramtype blob_auditing_policy_name: str + :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. + :return: An instance of LROPoller that returns either ServerBlobAuditingPolicy or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerBlobAuditingPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - blob_auditing_policy_name = kwargs.pop('blob_auditing_policy_name', "default") # type: str - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerBlobAuditingPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + blob_auditing_policy_name = kwargs.pop("blob_auditing_policy_name", "default") # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerBlobAuditingPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -453,36 +481,32 @@ def begin_create_or_update( blob_auditing_policy_name=blob_auditing_policy_name, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerBlobAuditingPolicy', pipeline_response) + deserialized = self._deserialize("ServerBlobAuditingPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_communication_links_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_communication_links_operations.py index 287cb59c94677..c914fdc6a14a8 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_communication_links_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_communication_links_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,166 +26,139 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_delete_request( - subscription_id: str, - resource_group_name: str, - server_name: str, - communication_link_name: str, - **kwargs: Any + resource_group_name: str, server_name: str, communication_link_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "communicationLinkName": _SERIALIZER.url("communication_link_name", communication_link_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "communicationLinkName": _SERIALIZER.url("communication_link_name", communication_link_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_get_request( - subscription_id: str, - resource_group_name: str, - server_name: str, - communication_link_name: str, - **kwargs: Any + resource_group_name: str, server_name: str, communication_link_name: str, subscription_id: str, **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', "2014-04-01")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "communicationLinkName": _SERIALIZER.url("communication_link_name", communication_link_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "communicationLinkName": _SERIALIZER.url("communication_link_name", communication_link_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - subscription_id: str, - resource_group_name: str, - server_name: str, - communication_link_name: str, - *, - json: Optional[_models.ServerCommunicationLink] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, server_name: str, communication_link_name: str, subscription_id: str, **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', "2014-04-01")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "communicationLinkName": _SERIALIZER.url("communication_link_name", communication_link_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "communicationLinkName": _SERIALIZER.url("communication_link_name", communication_link_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_server_request( - subscription_id: str, - resource_group_name: str, - server_name: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2014-04-01")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ServerCommunicationLinksOperations: """ @@ -202,51 +179,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - communication_link_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, communication_link_name: str, **kwargs: Any ) -> None: """Deletes a server communication link. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param communication_link_name: The name of the server communication link. + :param communication_link_name: The name of the server communication link. Required. :type communication_link_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, communication_link_name=communication_link_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -254,10 +220,9 @@ def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -267,53 +232,42 @@ def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - communication_link_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, communication_link_name: str, **kwargs: Any ) -> _models.ServerCommunicationLink: """Returns a server communication link. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param communication_link_name: The name of the server communication link. + :param communication_link_name: The name of the server communication link. Required. :type communication_link_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerCommunicationLink, or the result of cls(response) + :return: ServerCommunicationLink or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerCommunicationLink - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerCommunicationLink] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerCommunicationLink] - request = build_get_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, communication_link_name=communication_link_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -321,57 +275,60 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerCommunicationLink', pipeline_response) + deserialized = self._deserialize("ServerCommunicationLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, communication_link_name: str, - parameters: _models.ServerCommunicationLink, + parameters: Union[_models.ServerCommunicationLink, IO], **kwargs: Any ) -> Optional[_models.ServerCommunicationLink]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerCommunicationLink]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerCommunicationLink]] - _json = self._serialize.body(parameters, 'ServerCommunicationLink') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerCommunicationLink") - request = build_create_or_update_request_initial( - subscription_id=self._config.subscription_id, + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, communication_link_name=communication_link_name, + subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -379,10 +336,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [201, 202]: @@ -391,39 +347,40 @@ def _create_or_update_initial( deserialized = None if response.status_code == 201: - deserialized = self._deserialize('ServerCommunicationLink', pipeline_response) + deserialized = self._deserialize("ServerCommunicationLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, communication_link_name: str, parameters: _models.ServerCommunicationLink, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ServerCommunicationLink]: """Creates a server communication link. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param communication_link_name: The name of the server communication link. + :param communication_link_name: The name of the server communication link. Required. :type communication_link_name: str - :param parameters: The required parameters for creating a server communication link. + :param parameters: The required parameters for creating a server communication link. Required. :type parameters: ~azure.mgmt.sql.models.ServerCommunicationLink - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -435,20 +392,94 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ServerCommunicationLink or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerCommunicationLink] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + communication_link_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ServerCommunicationLink]: + """Creates a server communication link. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param communication_link_name: The name of the server communication link. Required. + :type communication_link_name: str + :param parameters: The required parameters for creating a server communication link. Required. + :type parameters: IO + :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 ServerCommunicationLink or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerCommunicationLink] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + communication_link_name: str, + parameters: Union[_models.ServerCommunicationLink, IO], + **kwargs: Any + ) -> LROPoller[_models.ServerCommunicationLink]: + """Creates a server communication link. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param communication_link_name: The name of the server communication link. Required. + :type communication_link_name: str + :param parameters: The required parameters for creating a server communication link. Is either + a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerCommunicationLink 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. + :return: An instance of LROPoller that returns either ServerCommunicationLink or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerCommunicationLink] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerCommunicationLink] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerCommunicationLink] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -457,82 +488,71 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerCommunicationLink', pipeline_response) + deserialized = self._deserialize("ServerCommunicationLink", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks/{communicationLinkName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.ServerCommunicationLinkListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.ServerCommunicationLink"]: """Gets a list of server communication links. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerCommunicationLinkListResult or the result of + :return: An iterator like instance of either ServerCommunicationLink or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerCommunicationLinkListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerCommunicationLink] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerCommunicationLinkListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerCommunicationLinkListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -540,16 +560,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -565,10 +576,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -578,8 +587,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/communicationLinks"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_connection_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_connection_policies_operations.py index b61a86b83f1ef..f0714d9dbd3ad 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_connection_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_connection_policies_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -39,117 +46,101 @@ 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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "connectionPolicyName": _SERIALIZER.url("connection_policy_name", connection_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "connectionPolicyName": _SERIALIZER.url("connection_policy_name", connection_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, server_name: str, connection_policy_name: Union[str, "_models.ConnectionPolicyName"], subscription_id: str, - *, - json: Optional[_models.ServerConnectionPolicy] = None, - content: Any = None, **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', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "connectionPolicyName": _SERIALIZER.url("connection_policy_name", connection_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "connectionPolicyName": _SERIALIZER.url("connection_policy_name", connection_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2021-05-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-05-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ServerConnectionPoliciesOperations: """ @@ -170,7 +161,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -182,39 +172,33 @@ def get( """Gets a server connection policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param connection_policy_name: The name of the connection policy. + :param connection_policy_name: The name of the connection policy. "default" Required. :type connection_policy_name: str or ~azure.mgmt.sql.models.ConnectionPolicyName - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerConnectionPolicy, or the result of cls(response) + :return: ServerConnectionPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerConnectionPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerConnectionPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerConnectionPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, connection_policy_name=connection_policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -222,49 +206,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerConnectionPolicy', pipeline_response) + deserialized = self._deserialize("ServerConnectionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, connection_policy_name: Union[str, "_models.ConnectionPolicyName"], - parameters: _models.ServerConnectionPolicy, + parameters: Union[_models.ServerConnectionPolicy, IO], **kwargs: Any ) -> Optional[_models.ServerConnectionPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerConnectionPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerConnectionPolicy]] - _json = self._serialize.body(parameters, 'ServerConnectionPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerConnectionPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, connection_policy_name=connection_policy_name, @@ -272,7 +258,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -280,10 +267,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -292,39 +278,117 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerConnectionPolicy', pipeline_response) + deserialized = self._deserialize("ServerConnectionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, connection_policy_name: Union[str, "_models.ConnectionPolicyName"], parameters: _models.ServerConnectionPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ServerConnectionPolicy]: """Updates a server connection policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param connection_policy_name: The name of the connection policy. + :param connection_policy_name: The name of the connection policy. "default" Required. :type connection_policy_name: str or ~azure.mgmt.sql.models.ConnectionPolicyName - :param parameters: The required parameters for updating a server connection policy. + :param parameters: The required parameters for updating a server connection policy. Required. :type parameters: ~azure.mgmt.sql.models.ServerConnectionPolicy - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ServerConnectionPolicy or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerConnectionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + connection_policy_name: Union[str, "_models.ConnectionPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ServerConnectionPolicy]: + """Updates a server connection policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param connection_policy_name: The name of the connection policy. "default" Required. + :type connection_policy_name: str or ~azure.mgmt.sql.models.ConnectionPolicyName + :param parameters: The required parameters for updating a server connection policy. Required. + :type parameters: IO + :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 ServerConnectionPolicy or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerConnectionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + connection_policy_name: Union[str, "_models.ConnectionPolicyName"], + parameters: Union[_models.ServerConnectionPolicy, IO], + **kwargs: Any + ) -> LROPoller[_models.ServerConnectionPolicy]: + """Updates a server connection policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param connection_policy_name: The name of the connection policy. "default" Required. + :type connection_policy_name: str or ~azure.mgmt.sql.models.ConnectionPolicyName + :param parameters: The required parameters for updating a server connection policy. Is either a + model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerConnectionPolicy 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 @@ -336,20 +400,17 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ServerConnectionPolicy or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerConnectionPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerConnectionPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerConnectionPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -358,82 +419,71 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerConnectionPolicy', pipeline_response) + deserialized = self._deserialize("ServerConnectionPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.ServerConnectionPolicyListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.ServerConnectionPolicy"]: """Lists connection policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-05-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerConnectionPolicyListResult or the result of + :return: An iterator like instance of either ServerConnectionPolicy or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerConnectionPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerConnectionPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-05-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerConnectionPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerConnectionPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -441,16 +491,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -466,10 +507,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -479,8 +518,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_dev_ops_audit_settings_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_dev_ops_audit_settings_operations.py index 9d76cc7743d63..927367ccfd0e2 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_dev_ops_audit_settings_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_dev_ops_audit_settings_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,134 +26,117 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( - resource_group_name: str, - server_name: str, - dev_ops_auditing_settings_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, dev_ops_auditing_settings_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings/{devOpsAuditingSettingsName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings/{devOpsAuditingSettingsName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "devOpsAuditingSettingsName": _SERIALIZER.url("dev_ops_auditing_settings_name", dev_ops_auditing_settings_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "devOpsAuditingSettingsName": _SERIALIZER.url( + "dev_ops_auditing_settings_name", dev_ops_auditing_settings_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - resource_group_name: str, - server_name: str, - dev_ops_auditing_settings_name: str, - subscription_id: str, - *, - json: Optional[_models.ServerDevOpsAuditingSettings] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, server_name: str, dev_ops_auditing_settings_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings/{devOpsAuditingSettingsName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings/{devOpsAuditingSettingsName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "devOpsAuditingSettingsName": _SERIALIZER.url("dev_ops_auditing_settings_name", dev_ops_auditing_settings_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "devOpsAuditingSettingsName": _SERIALIZER.url( + "dev_ops_auditing_settings_name", dev_ops_auditing_settings_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ServerDevOpsAuditSettingsOperations: """ @@ -170,52 +157,41 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - dev_ops_auditing_settings_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, dev_ops_auditing_settings_name: str, **kwargs: Any ) -> _models.ServerDevOpsAuditingSettings: """Gets a server's DevOps audit settings. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param dev_ops_auditing_settings_name: The name of the devops audit settings. This should - always be 'default'. + always be 'default'. Required. :type dev_ops_auditing_settings_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerDevOpsAuditingSettings, or the result of cls(response) + :return: ServerDevOpsAuditingSettings or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerDevOpsAuditingSettings - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerDevOpsAuditingSettings] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerDevOpsAuditingSettings] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, dev_ops_auditing_settings_name=dev_ops_auditing_settings_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -223,49 +199,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerDevOpsAuditingSettings', pipeline_response) + deserialized = self._deserialize("ServerDevOpsAuditingSettings", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings/{devOpsAuditingSettingsName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings/{devOpsAuditingSettingsName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, dev_ops_auditing_settings_name: str, - parameters: _models.ServerDevOpsAuditingSettings, + parameters: Union[_models.ServerDevOpsAuditingSettings, IO], **kwargs: Any ) -> Optional[_models.ServerDevOpsAuditingSettings]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerDevOpsAuditingSettings]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerDevOpsAuditingSettings]] - _json = self._serialize.body(parameters, 'ServerDevOpsAuditingSettings') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerDevOpsAuditingSettings") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, dev_ops_auditing_settings_name=dev_ops_auditing_settings_name, @@ -273,7 +251,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -281,10 +260,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -293,40 +271,81 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerDevOpsAuditingSettings', pipeline_response) + deserialized = self._deserialize("ServerDevOpsAuditingSettings", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings/{devOpsAuditingSettingsName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings/{devOpsAuditingSettingsName}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, dev_ops_auditing_settings_name: str, parameters: _models.ServerDevOpsAuditingSettings, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ServerDevOpsAuditingSettings]: """Creates or updates a server's DevOps audit settings. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param dev_ops_auditing_settings_name: The name of the devops audit settings. This should - always be 'default'. + always be 'default'. Required. :type dev_ops_auditing_settings_name: str - :param parameters: Properties of DevOps audit settings. + :param parameters: Properties of DevOps audit settings. Required. :type parameters: ~azure.mgmt.sql.models.ServerDevOpsAuditingSettings - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ServerDevOpsAuditingSettings or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerDevOpsAuditingSettings] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + dev_ops_auditing_settings_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ServerDevOpsAuditingSettings]: + """Creates or updates a server's DevOps audit settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param dev_ops_auditing_settings_name: The name of the devops audit settings. This should + always be 'default'. Required. + :type dev_ops_auditing_settings_name: str + :param parameters: Properties of DevOps audit settings. Required. + :type parameters: IO + :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 @@ -338,20 +357,56 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ServerDevOpsAuditingSettings or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerDevOpsAuditingSettings] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + dev_ops_auditing_settings_name: str, + parameters: Union[_models.ServerDevOpsAuditingSettings, IO], + **kwargs: Any + ) -> LROPoller[_models.ServerDevOpsAuditingSettings]: + """Creates or updates a server's DevOps audit settings. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param dev_ops_auditing_settings_name: The name of the devops audit settings. This should + always be 'default'. Required. + :type dev_ops_auditing_settings_name: str + :param parameters: Properties of DevOps audit settings. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ServerDevOpsAuditingSettings 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. + :return: An instance of LROPoller that returns either ServerDevOpsAuditingSettings or the + result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerDevOpsAuditingSettings] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerDevOpsAuditingSettings] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerDevOpsAuditingSettings] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -360,83 +415,73 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerDevOpsAuditingSettings', pipeline_response) + deserialized = self._deserialize("ServerDevOpsAuditingSettings", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - lro_options={'final-state-via': 'azure-async-operation'}, - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast( + PollingMethod, ARMPolling(lro_delay, lro_options={"final-state-via": "azure-async-operation"}, **kwargs) + ) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/devOpsAuditingSettings/{devOpsAuditingSettingsName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings/{devOpsAuditingSettingsName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.ServerDevOpsAuditSettingsListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.ServerDevOpsAuditingSettings"]: """Lists DevOps audit settings of a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerDevOpsAuditSettingsListResult or the result - of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerDevOpsAuditSettingsListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServerDevOpsAuditingSettings or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerDevOpsAuditingSettings] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerDevOpsAuditSettingsListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerDevOpsAuditSettingsListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -444,16 +489,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -469,10 +505,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -482,8 +516,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/devOpsAuditingSettings"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_dns_aliases_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_dns_aliases_operations.py index 8ca08945c9b94..8bf4a3e680a1e 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_dns_aliases_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_dns_aliases_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,205 +26,171 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( - resource_group_name: str, - server_name: str, - dns_alias_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, dns_alias_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "dnsAliasName": _SERIALIZER.url("dns_alias_name", dns_alias_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "dnsAliasName": _SERIALIZER.url("dns_alias_name", dns_alias_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - resource_group_name: str, - server_name: str, - dns_alias_name: str, - subscription_id: str, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, server_name: str, dns_alias_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "dnsAliasName": _SERIALIZER.url("dns_alias_name", dns_alias_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "dnsAliasName": _SERIALIZER.url("dns_alias_name", dns_alias_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_delete_request_initial( - resource_group_name: str, - server_name: str, - dns_alias_name: str, - subscription_id: str, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_delete_request( + resource_group_name: str, server_name: str, dns_alias_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "dnsAliasName": _SERIALIZER.url("dns_alias_name", dns_alias_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "dnsAliasName": _SERIALIZER.url("dns_alias_name", dns_alias_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_acquire_request_initial( - resource_group_name: str, - server_name: str, - dns_alias_name: str, - subscription_id: str, - *, - json: Optional[_models.ServerDnsAliasAcquisition] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_acquire_request( + resource_group_name: str, server_name: str, dns_alias_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}/acquire") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}/acquire", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "dnsAliasName": _SERIALIZER.url("dns_alias_name", dns_alias_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "dnsAliasName": _SERIALIZER.url("dns_alias_name", dns_alias_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) + class ServerDnsAliasesOperations: """ @@ -241,51 +211,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - dns_alias_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, dns_alias_name: str, **kwargs: Any ) -> _models.ServerDnsAlias: """Gets a server DNS alias. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server that the alias is pointing to. + :param server_name: The name of the server that the alias is pointing to. Required. :type server_name: str - :param dns_alias_name: The name of the server dns alias. + :param dns_alias_name: The name of the server dns alias. Required. :type dns_alias_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerDnsAlias, or the result of cls(response) + :return: ServerDnsAlias or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerDnsAlias - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerDnsAlias] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerDnsAlias] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, dns_alias_name=dns_alias_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -293,52 +252,43 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore def _create_or_update_initial( - self, - resource_group_name: str, - server_name: str, - dns_alias_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, dns_alias_name: str, **kwargs: Any ) -> Optional[_models.ServerDnsAlias]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerDnsAlias]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerDnsAlias]] - - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, dns_alias_name=dns_alias_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._create_or_update_initial.metadata['url'], + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -346,10 +296,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -358,39 +307,31 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ServerDnsAlias", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore @distributed_trace def begin_create_or_update( - self, - resource_group_name: str, - server_name: str, - dns_alias_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, dns_alias_name: str, **kwargs: Any ) -> LROPoller[_models.ServerDnsAlias]: """Creates a server DNS alias. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server that the alias is pointing to. + :param server_name: The name of the server that the alias is pointing to. Required. :type server_name: str - :param dns_alias_name: The name of the server dns alias. + :param dns_alias_name: The name of the server dns alias. Required. :type dns_alias_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -402,85 +343,71 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ServerDnsAlias or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerDnsAlias] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerDnsAlias] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerDnsAlias] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, dns_alias_name=dns_alias_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - dns_alias_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, dns_alias_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, dns_alias_name=dns_alias_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -488,10 +415,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -501,29 +427,21 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - dns_alias_name: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, server_name: str, dns_alias_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes the server DNS alias with the given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server that the alias is pointing to. + :param server_name: The name of the server that the alias is pointing to. Required. :type server_name: str - :param dns_alias_name: The name of the server dns alias. + :param dns_alias_name: The name of the server dns alias. Required. :type dns_alias_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -534,99 +452,84 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, dns_alias_name=dns_alias_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.ServerDnsAliasListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.ServerDnsAlias"]: """Gets a list of server DNS aliases for a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server that the alias is pointing to. + :param server_name: The name of the server that the alias is pointing to. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerDnsAliasListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerDnsAliasListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServerDnsAlias or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerDnsAlias] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerDnsAliasListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerDnsAliasListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -634,16 +537,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -659,10 +553,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -672,35 +564,37 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases"} # type: ignore def _acquire_initial( self, resource_group_name: str, server_name: str, dns_alias_name: str, - parameters: _models.ServerDnsAliasAcquisition, + parameters: Union[_models.ServerDnsAliasAcquisition, IO], **kwargs: Any ) -> Optional[_models.ServerDnsAlias]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerDnsAlias]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerDnsAlias]] - _json = self._serialize.body(parameters, 'ServerDnsAliasAcquisition') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerDnsAliasAcquisition") - request = build_acquire_request_initial( + request = build_acquire_request( resource_group_name=resource_group_name, server_name=server_name, dns_alias_name=dns_alias_name, @@ -708,7 +602,8 @@ def _acquire_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._acquire_initial.metadata['url'], + content=_content, + template_url=self._acquire_initial.metadata["url"], headers=_headers, params=_params, ) @@ -716,10 +611,9 @@ def _acquire_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -728,39 +622,40 @@ def _acquire_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _acquire_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}/acquire"} # type: ignore + _acquire_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}/acquire"} # type: ignore - - @distributed_trace + @overload def begin_acquire( self, resource_group_name: str, server_name: str, dns_alias_name: str, parameters: _models.ServerDnsAliasAcquisition, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ServerDnsAlias]: """Acquires server DNS alias from another server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server that the alias is pointing to. + :param server_name: The name of the server that the alias is pointing to. Required. :type server_name: str - :param dns_alias_name: The name of the server dns alias. + :param dns_alias_name: The name of the server dns alias. Required. :type dns_alias_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.ServerDnsAliasAcquisition - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -772,20 +667,93 @@ def begin_acquire( :return: An instance of LROPoller that returns either ServerDnsAlias or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerDnsAlias] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_acquire( + self, + resource_group_name: str, + server_name: str, + dns_alias_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ServerDnsAlias]: + """Acquires server DNS alias from another server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server that the alias is pointing to. Required. + :type server_name: str + :param dns_alias_name: The name of the server dns alias. Required. + :type dns_alias_name: str + :param parameters: Required. + :type parameters: IO + :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 ServerDnsAlias or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerDnsAlias] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_acquire( + self, + resource_group_name: str, + server_name: str, + dns_alias_name: str, + parameters: Union[_models.ServerDnsAliasAcquisition, IO], + **kwargs: Any + ) -> LROPoller[_models.ServerDnsAlias]: + """Acquires server DNS alias from another server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server that the alias is pointing to. Required. + :type server_name: str + :param dns_alias_name: The name of the server dns alias. Required. + :type dns_alias_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerDnsAliasAcquisition 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. + :return: An instance of LROPoller that returns either ServerDnsAlias or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerDnsAlias] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerDnsAlias] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerDnsAlias] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._acquire_initial( # type: ignore resource_group_name=resource_group_name, @@ -794,36 +762,32 @@ def begin_acquire( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerDnsAlias', pipeline_response) + deserialized = self._deserialize("ServerDnsAlias", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_acquire.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}/acquire"} # type: ignore + begin_acquire.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/dnsAliases/{dnsAliasName}/acquire"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_keys_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_keys_operations.py index cb5215f94fe2a..07929abf151d4 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_keys_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_keys_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,166 +26,139 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - server_name: str, - key_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, key_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "keyName": _SERIALIZER.url("key_name", key_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "keyName": _SERIALIZER.url("key_name", key_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - resource_group_name: str, - server_name: str, - key_name: str, - subscription_id: str, - *, - json: Optional[_models.ServerKey] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, server_name: str, key_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "keyName": _SERIALIZER.url("key_name", key_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "keyName": _SERIALIZER.url("key_name", key_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) - - -def build_delete_request_initial( - resource_group_name: str, - server_name: str, - key_name: str, - subscription_id: str, - **kwargs: Any + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_delete_request( + resource_group_name: str, server_name: str, key_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "keyName": _SERIALIZER.url("key_name", key_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "keyName": _SERIALIZER.url("key_name", key_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) class ServerKeysOperations: """ @@ -202,48 +179,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.ServerKeyListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.ServerKey"]: """Gets a list of server keys. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerKeyListResult or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerKeyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServerKey or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerKey] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerKeyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerKeyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -251,16 +220,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -276,10 +236,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -289,56 +247,42 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys"} # type: ignore @distributed_trace - def get( - self, - resource_group_name: str, - server_name: str, - key_name: str, - **kwargs: Any - ) -> _models.ServerKey: + def get(self, resource_group_name: str, server_name: str, key_name: str, **kwargs: Any) -> _models.ServerKey: """Gets a server key. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param key_name: The name of the server key to be retrieved. + :param key_name: The name of the server key to be retrieved. Required. :type key_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerKey, or the result of cls(response) + :return: ServerKey or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerKey - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerKey] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerKey] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, key_name=key_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -346,49 +290,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerKey', pipeline_response) + deserialized = self._deserialize("ServerKey", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, key_name: str, - parameters: _models.ServerKey, + parameters: Union[_models.ServerKey, IO], **kwargs: Any ) -> Optional[_models.ServerKey]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerKey]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerKey]] - _json = self._serialize.body(parameters, 'ServerKey') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerKey") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, key_name=key_name, @@ -396,7 +342,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -404,10 +351,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -416,45 +362,46 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerKey', pipeline_response) + deserialized = self._deserialize("ServerKey", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ServerKey', pipeline_response) + deserialized = self._deserialize("ServerKey", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, key_name: str, parameters: _models.ServerKey, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ServerKey]: """Creates or updates a server key. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param key_name: The name of the server key to be operated on (updated or created). The key name is required to be in the format of 'vault_key_version'. For example, if the keyId is https://YourVaultName.vault.azure.net/keys/YourKeyName/YourKeyVersion, then the server key name - should be formatted as: YourVaultName_YourKeyName_YourKeyVersion. + should be formatted as: YourVaultName_YourKeyName_YourKeyVersion. Required. :type key_name: str - :param parameters: The requested server key resource state. + :param parameters: The requested server key resource state. Required. :type parameters: ~azure.mgmt.sql.models.ServerKey - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -465,20 +412,98 @@ def begin_create_or_update( Retry-After header is present. :return: An instance of LROPoller that returns either ServerKey or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerKey] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + key_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ServerKey]: + """Creates or updates a server key. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param key_name: The name of the server key to be operated on (updated or created). The key + name is required to be in the format of 'vault_key_version'. For example, if the keyId is + https://YourVaultName.vault.azure.net/keys/YourKeyName/YourKeyVersion, then the server key name + should be formatted as: YourVaultName_YourKeyName_YourKeyVersion. Required. + :type key_name: str + :param parameters: The requested server key resource state. Required. + :type parameters: IO + :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 ServerKey or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerKey] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + key_name: str, + parameters: Union[_models.ServerKey, IO], + **kwargs: Any + ) -> LROPoller[_models.ServerKey]: + """Creates or updates a server key. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param key_name: The name of the server key to be operated on (updated or created). The key + name is required to be in the format of 'vault_key_version'. For example, if the keyId is + https://YourVaultName.vault.azure.net/keys/YourKeyName/YourKeyVersion, then the server key name + should be formatted as: YourVaultName_YourKeyName_YourKeyVersion. Required. + :type key_name: str + :param parameters: The requested server key resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerKey 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. + :return: An instance of LROPoller that returns either ServerKey or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerKey] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerKey] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerKey] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -487,66 +512,55 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerKey', pipeline_response) + deserialized = self._deserialize("ServerKey", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - key_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, key_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, key_name=key_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -554,10 +568,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -567,29 +580,19 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - key_name: str, - **kwargs: Any - ) -> LROPoller[None]: + def begin_delete(self, resource_group_name: str, server_name: str, key_name: str, **kwargs: Any) -> LROPoller[None]: """Deletes the server key with the given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param key_name: The name of the server key to be deleted. + :param key_name: The name of the server key to be deleted. Required. :type key_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -600,53 +603,46 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, key_name=key_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/keys/{keyName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_operations_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_operations_operations.py index c3f41b3ac9d13..a582515671740 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_operations_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_operations_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,48 +24,46 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/operations") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/operations", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ServerOperationsOperations: """ @@ -82,49 +84,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.ServerOperationListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.ServerOperation"]: """Gets a list of operations performed on the server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerOperationListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerOperationListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServerOperation or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerOperation] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerOperationListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerOperationListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -132,16 +125,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -157,10 +141,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -170,8 +152,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/operations"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/operations"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_security_alert_policies_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_security_alert_policies_operations.py index 94e6765c9f686..05c1a2df670ae 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_security_alert_policies_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_security_alert_policies_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -39,117 +46,101 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "securityAlertPolicyName": _SERIALIZER.url("security_alert_policy_name", security_alert_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "securityAlertPolicyName": _SERIALIZER.url("security_alert_policy_name", security_alert_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, server_name: str, security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], subscription_id: str, - *, - json: Optional[_models.ServerSecurityAlertPolicy] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "securityAlertPolicyName": _SERIALIZER.url("security_alert_policy_name", security_alert_policy_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "securityAlertPolicyName": _SERIALIZER.url("security_alert_policy_name", security_alert_policy_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ServerSecurityAlertPoliciesOperations: """ @@ -170,7 +161,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -182,39 +172,33 @@ def get( """Get a server's security alert policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param security_alert_policy_name: The name of the security alert policy. + :param security_alert_policy_name: The name of the security alert policy. "Default" Required. :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerSecurityAlertPolicy, or the result of cls(response) + :return: ServerSecurityAlertPolicy or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerSecurityAlertPolicy - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerSecurityAlertPolicy] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerSecurityAlertPolicy] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, security_alert_policy_name=security_alert_policy_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -222,49 +206,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ServerSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], - parameters: _models.ServerSecurityAlertPolicy, + parameters: Union[_models.ServerSecurityAlertPolicy, IO], **kwargs: Any ) -> Optional[_models.ServerSecurityAlertPolicy]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerSecurityAlertPolicy]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerSecurityAlertPolicy]] - _json = self._serialize.body(parameters, 'ServerSecurityAlertPolicy') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerSecurityAlertPolicy") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, security_alert_policy_name=security_alert_policy_name, @@ -272,7 +258,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -280,10 +267,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -292,39 +278,117 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ServerSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], parameters: _models.ServerSecurityAlertPolicy, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ServerSecurityAlertPolicy]: """Creates or updates a threat detection policy. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param security_alert_policy_name: The name of the threat detection policy. + :param security_alert_policy_name: The name of the threat detection policy. "Default" Required. :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName - :param parameters: The server security alert policy. + :param parameters: The server security alert policy. Required. :type parameters: ~azure.mgmt.sql.models.ServerSecurityAlertPolicy - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ServerSecurityAlertPolicy or the result + of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerSecurityAlertPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ServerSecurityAlertPolicy]: + """Creates or updates a threat detection policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param security_alert_policy_name: The name of the threat detection policy. "Default" Required. + :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName + :param parameters: The server security alert policy. Required. + :type parameters: IO + :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 ServerSecurityAlertPolicy or the result + of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerSecurityAlertPolicy] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + security_alert_policy_name: Union[str, "_models.SecurityAlertPolicyName"], + parameters: Union[_models.ServerSecurityAlertPolicy, IO], + **kwargs: Any + ) -> LROPoller[_models.ServerSecurityAlertPolicy]: + """Creates or updates a threat detection policy. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param security_alert_policy_name: The name of the threat detection policy. "Default" Required. + :type security_alert_policy_name: str or ~azure.mgmt.sql.models.SecurityAlertPolicyName + :param parameters: The server security alert policy. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ServerSecurityAlertPolicy 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 @@ -336,20 +400,17 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ServerSecurityAlertPolicy or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerSecurityAlertPolicy] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerSecurityAlertPolicy] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerSecurityAlertPolicy] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -358,83 +419,71 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerSecurityAlertPolicy', pipeline_response) + deserialized = self._deserialize("ServerSecurityAlertPolicy", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.LogicalServerSecurityAlertPolicyListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.ServerSecurityAlertPolicy"]: """Get the server's threat detection policies. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LogicalServerSecurityAlertPolicyListResult or the - result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LogicalServerSecurityAlertPolicyListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServerSecurityAlertPolicy or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerSecurityAlertPolicy] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LogicalServerSecurityAlertPolicyListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LogicalServerSecurityAlertPolicyListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -442,16 +491,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -467,10 +507,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -480,8 +518,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/securityAlertPolicies"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_trust_certificates_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_trust_certificates_operations.py index 1f4c7a273104a..6c49ca82fbaa4 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_trust_certificates_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_trust_certificates_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,166 +26,139 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_instance_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - managed_instance_name: str, - certificate_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, certificate_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "certificateName": _SERIALIZER.url("certificate_name", certificate_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "certificateName": _SERIALIZER.url("certificate_name", certificate_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - resource_group_name: str, - managed_instance_name: str, - certificate_name: str, - subscription_id: str, - *, - json: Optional[_models.ServerTrustCertificate] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, managed_instance_name: str, certificate_name: str, subscription_id: str, **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', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "certificateName": _SERIALIZER.url("certificate_name", certificate_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "certificateName": _SERIALIZER.url("certificate_name", certificate_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) - - -def build_delete_request_initial( - resource_group_name: str, - managed_instance_name: str, - certificate_name: str, - subscription_id: str, - **kwargs: Any + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_delete_request( + resource_group_name: str, managed_instance_name: str, certificate_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "certificateName": _SERIALIZER.url("certificate_name", certificate_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "certificateName": _SERIALIZER.url("certificate_name", certificate_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) class ServerTrustCertificatesOperations: """ @@ -202,50 +179,42 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> Iterable[_models.ServerTrustCertificatesListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.ServerTrustCertificate"]: """Gets a list of server trust certificates that were uploaded from box to the given Sql Managed Instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerTrustCertificatesListResult or the result of + :return: An iterator like instance of either ServerTrustCertificate or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerTrustCertificatesListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerTrustCertificate] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerTrustCertificatesListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerTrustCertificatesListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -253,16 +222,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -278,10 +238,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -291,56 +249,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - managed_instance_name: str, - certificate_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, certificate_name: str, **kwargs: Any ) -> _models.ServerTrustCertificate: """Gets a server trust certificate that was uploaded from box to Sql Managed Instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param certificate_name: Name of of the certificate to get. + :param certificate_name: Name of of the certificate to get. Required. :type certificate_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerTrustCertificate, or the result of cls(response) + :return: ServerTrustCertificate or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerTrustCertificate - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerTrustCertificate] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerTrustCertificate] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, certificate_name=certificate_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -348,49 +294,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerTrustCertificate', pipeline_response) + deserialized = self._deserialize("ServerTrustCertificate", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, managed_instance_name: str, certificate_name: str, - parameters: _models.ServerTrustCertificate, + parameters: Union[_models.ServerTrustCertificate, IO], **kwargs: Any ) -> Optional[_models.ServerTrustCertificate]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerTrustCertificate]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerTrustCertificate]] - _json = self._serialize.body(parameters, 'ServerTrustCertificate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerTrustCertificate") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, certificate_name=certificate_name, @@ -398,7 +346,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -406,10 +355,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -418,42 +366,43 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerTrustCertificate', pipeline_response) + deserialized = self._deserialize("ServerTrustCertificate", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ServerTrustCertificate', pipeline_response) + deserialized = self._deserialize("ServerTrustCertificate", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, managed_instance_name: str, certificate_name: str, parameters: _models.ServerTrustCertificate, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ServerTrustCertificate]: """Uploads a server trust certificate from box to Sql Managed Instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param certificate_name: Name of of the certificate to upload. + :param certificate_name: Name of of the certificate to upload. Required. :type certificate_name: str - :param parameters: The server trust certificate info. + :param parameters: The server trust certificate info. Required. :type parameters: ~azure.mgmt.sql.models.ServerTrustCertificate - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -465,20 +414,94 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ServerTrustCertificate or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerTrustCertificate] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + certificate_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ServerTrustCertificate]: + """Uploads a server trust certificate from box to Sql Managed Instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param certificate_name: Name of of the certificate to upload. Required. + :type certificate_name: str + :param parameters: The server trust certificate info. Required. + :type parameters: IO + :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 ServerTrustCertificate or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerTrustCertificate] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + certificate_name: str, + parameters: Union[_models.ServerTrustCertificate, IO], + **kwargs: Any + ) -> LROPoller[_models.ServerTrustCertificate]: + """Uploads a server trust certificate from box to Sql Managed Instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param certificate_name: Name of of the certificate to upload. Required. + :type certificate_name: str + :param parameters: The server trust certificate info. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ServerTrustCertificate 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. + :return: An instance of LROPoller that returns either ServerTrustCertificate or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerTrustCertificate] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerTrustCertificate] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerTrustCertificate] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -487,66 +510,55 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerTrustCertificate', pipeline_response) + deserialized = self._deserialize("ServerTrustCertificate", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - certificate_name: str, - **kwargs: Any + self, resource_group_name: str, managed_instance_name: str, certificate_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, certificate_name=certificate_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -554,10 +566,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -567,29 +578,21 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - managed_instance_name: str, - certificate_name: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, managed_instance_name: str, certificate_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes a server trust certificate that was uploaded from box to Sql Managed Instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param certificate_name: Name of of the certificate to delete. + :param certificate_name: Name of of the certificate to delete. Required. :type certificate_name: str - :keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -600,53 +603,46 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, certificate_name=certificate_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustCertificates/{certificateName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_trust_groups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_trust_groups_operations.py index d1c5c751e6a51..c313d22c6affd 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_trust_groups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_trust_groups_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,203 +26,170 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( - resource_group_name: str, - location_name: str, - server_trust_group_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, location_name: str, server_trust_group_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "serverTrustGroupName": _SERIALIZER.url("server_trust_group_name", server_trust_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "serverTrustGroupName": _SERIALIZER.url("server_trust_group_name", server_trust_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - resource_group_name: str, - location_name: str, - server_trust_group_name: str, - subscription_id: str, - *, - json: Optional[_models.ServerTrustGroup] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, location_name: str, server_trust_group_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "serverTrustGroupName": _SERIALIZER.url("server_trust_group_name", server_trust_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "serverTrustGroupName": _SERIALIZER.url("server_trust_group_name", server_trust_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) - - -def build_delete_request_initial( - resource_group_name: str, - location_name: str, - server_trust_group_name: str, - subscription_id: str, - **kwargs: Any + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_delete_request( + resource_group_name: str, location_name: str, server_trust_group_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "serverTrustGroupName": _SERIALIZER.url("server_trust_group_name", server_trust_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "serverTrustGroupName": _SERIALIZER.url("server_trust_group_name", server_trust_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_location_request( - resource_group_name: str, - location_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, location_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_instance_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustGroups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustGroups", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ServerTrustGroupsOperations: """ @@ -239,51 +210,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( - self, - resource_group_name: str, - location_name: str, - server_trust_group_name: str, - **kwargs: Any + self, resource_group_name: str, location_name: str, server_trust_group_name: str, **kwargs: Any ) -> _models.ServerTrustGroup: """Gets a server trust group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param server_trust_group_name: The name of the server trust group. + :param server_trust_group_name: The name of the server trust group. Required. :type server_trust_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerTrustGroup, or the result of cls(response) + :return: ServerTrustGroup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerTrustGroup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerTrustGroup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerTrustGroup] - request = build_get_request( resource_group_name=resource_group_name, location_name=location_name, server_trust_group_name=server_trust_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -291,49 +251,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerTrustGroup', pipeline_response) + deserialized = self._deserialize("ServerTrustGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, location_name: str, server_trust_group_name: str, - parameters: _models.ServerTrustGroup, + parameters: Union[_models.ServerTrustGroup, IO], **kwargs: Any ) -> Optional[_models.ServerTrustGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ServerTrustGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ServerTrustGroup]] - _json = self._serialize.body(parameters, 'ServerTrustGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerTrustGroup") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, location_name=location_name, server_trust_group_name=server_trust_group_name, @@ -341,7 +303,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -349,10 +312,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -361,42 +323,120 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ServerTrustGroup', pipeline_response) + deserialized = self._deserialize("ServerTrustGroup", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ServerTrustGroup', pipeline_response) + deserialized = self._deserialize("ServerTrustGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, location_name: str, server_trust_group_name: str, parameters: _models.ServerTrustGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ServerTrustGroup]: """Creates or updates a server trust group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param server_trust_group_name: The name of the server trust group. + :param server_trust_group_name: The name of the server trust group. Required. :type server_trust_group_name: str - :param parameters: The server trust group parameters. + :param parameters: The server trust group parameters. Required. :type parameters: ~azure.mgmt.sql.models.ServerTrustGroup - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 ServerTrustGroup or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerTrustGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + location_name: str, + server_trust_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ServerTrustGroup]: + """Creates or updates a server trust group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param location_name: The name of the region where the resource is located. Required. + :type location_name: str + :param server_trust_group_name: The name of the server trust group. Required. + :type server_trust_group_name: str + :param parameters: The server trust group parameters. Required. + :type parameters: IO + :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 ServerTrustGroup or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerTrustGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + location_name: str, + server_trust_group_name: str, + parameters: Union[_models.ServerTrustGroup, IO], + **kwargs: Any + ) -> LROPoller[_models.ServerTrustGroup]: + """Creates or updates a server trust group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param location_name: The name of the region where the resource is located. Required. + :type location_name: str + :param server_trust_group_name: The name of the server trust group. Required. + :type server_trust_group_name: str + :param parameters: The server trust group parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ServerTrustGroup 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 @@ -408,20 +448,17 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either ServerTrustGroup or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ServerTrustGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerTrustGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerTrustGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -430,66 +467,55 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ServerTrustGroup', pipeline_response) + deserialized = self._deserialize("ServerTrustGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - location_name: str, - server_trust_group_name: str, - **kwargs: Any + self, resource_group_name: str, location_name: str, server_trust_group_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, location_name=location_name, server_trust_group_name=server_trust_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -497,10 +523,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -510,29 +535,21 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - location_name: str, - server_trust_group_name: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, location_name: str, server_trust_group_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes a server trust group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param server_trust_group_name: The name of the server trust group. + :param server_trust_group_name: The name of the server trust group. Required. :type server_trust_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -543,99 +560,84 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, location_name=location_name, server_trust_group_name=server_trust_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups/{serverTrustGroupName}"} # type: ignore @distributed_trace def list_by_location( - self, - resource_group_name: str, - location_name: str, - **kwargs: Any - ) -> Iterable[_models.ServerTrustGroupListResult]: + self, resource_group_name: str, location_name: str, **kwargs: Any + ) -> Iterable["_models.ServerTrustGroup"]: """Lists a server trust group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerTrustGroupListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerTrustGroupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServerTrustGroup or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerTrustGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerTrustGroupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerTrustGroupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_location_request( resource_group_name=resource_group_name, location_name=location_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_location.metadata['url'], + template_url=self.list_by_location.metadata["url"], headers=_headers, params=_params, ) @@ -643,16 +645,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_location_request( - resource_group_name=resource_group_name, - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -668,10 +661,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -681,54 +672,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups"} # type: ignore + list_by_location.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/locations/{locationName}/serverTrustGroups"} # type: ignore @distributed_trace def list_by_instance( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> Iterable[_models.ServerTrustGroupListResult]: + self, resource_group_name: str, managed_instance_name: str, **kwargs: Any + ) -> Iterable["_models.ServerTrustGroup"]: """Gets a server trust groups by instance name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerTrustGroupListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerTrustGroupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServerTrustGroup or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerTrustGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerTrustGroupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerTrustGroupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_instance.metadata['url'], + template_url=self.list_by_instance.metadata["url"], headers=_headers, params=_params, ) @@ -736,16 +717,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_request( - resource_group_name=resource_group_name, - managed_instance_name=managed_instance_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -761,10 +733,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -774,8 +744,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_instance.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustGroups"} # type: ignore + list_by_instance.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/serverTrustGroups"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_usages_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_usages_operations.py index 99e8fd8566afe..8f22f8f4b3df2 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_usages_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_usages_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,48 +24,46 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_server_request( - subscription_id: str, - resource_group_name: str, - server_name: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2014-04-01")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/usages") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/usages", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ServerUsagesOperations: """ @@ -82,49 +84,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.ServerUsageListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.ServerUsage"]: """Returns server usages. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerUsageListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerUsageListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServerUsage or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerUsage] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerUsageListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerUsageListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -132,16 +125,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -157,10 +141,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -170,8 +152,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/usages"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/usages"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_vulnerability_assessments_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_vulnerability_assessments_operations.py index fbc0072eaaae9..d09400ea144e0 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_vulnerability_assessments_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_server_vulnerability_assessments_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -37,33 +44,32 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( @@ -71,46 +77,40 @@ def build_create_or_update_request( server_name: str, vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], subscription_id: str, - *, - json: Optional[_models.ServerVulnerabilityAssessment] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_delete_request( @@ -122,64 +122,59 @@ def build_delete_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "vulnerabilityAssessmentName": _SERIALIZER.url("vulnerability_assessment_name", vulnerability_assessment_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "vulnerabilityAssessmentName": _SERIALIZER.url( + "vulnerability_assessment_name", vulnerability_assessment_name, "str" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ServerVulnerabilityAssessmentsOperations: """ @@ -200,7 +195,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -212,39 +206,35 @@ def get( """Gets the server's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param server_name: The name of the server for which the vulnerability assessment is defined. + Required. :type server_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServerVulnerabilityAssessment, or the result of cls(response) + :return: ServerVulnerabilityAssessment or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerVulnerabilityAssessment - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerVulnerabilityAssessment] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerVulnerabilityAssessment] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -252,33 +242,33 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServerVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("ServerVulnerabilityAssessment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, server_name: str, vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], parameters: _models.ServerVulnerabilityAssessment, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.ServerVulnerabilityAssessment: """Creates or updates the server's vulnerability assessment. Learn more about setting SQL @@ -286,35 +276,109 @@ def create_or_update( https://docs.microsoft.com/azure/azure-sql/database/sql-database-vulnerability-assessment-storage. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param server_name: The name of the server for which the vulnerability assessment is defined. + Required. :type server_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :param parameters: The requested resource. + :param parameters: The requested resource. Required. :type parameters: ~azure.mgmt.sql.models.ServerVulnerabilityAssessment - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: ServerVulnerabilityAssessment, or the result of cls(response) + :return: ServerVulnerabilityAssessment or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServerVulnerabilityAssessment - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.ServerVulnerabilityAssessment: + """Creates or updates the server's vulnerability assessment. Learn more about setting SQL + vulnerability assessment with managed identity - + https://docs.microsoft.com/azure/azure-sql/database/sql-database-vulnerability-assessment-storage. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server for which the vulnerability assessment is defined. + Required. + :type server_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param parameters: The requested resource. Required. + :type parameters: IO + :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: ServerVulnerabilityAssessment or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ServerVulnerabilityAssessment + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + vulnerability_assessment_name: Union[str, "_models.VulnerabilityAssessmentName"], + parameters: Union[_models.ServerVulnerabilityAssessment, IO], + **kwargs: Any + ) -> _models.ServerVulnerabilityAssessment: + """Creates or updates the server's vulnerability assessment. Learn more about setting SQL + vulnerability assessment with managed identity - + https://docs.microsoft.com/azure/azure-sql/database/sql-database-vulnerability-assessment-storage. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server for which the vulnerability assessment is defined. + Required. + :type server_name: str + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. + :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName + :param parameters: The requested resource. Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.ServerVulnerabilityAssessment 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 + :return: ServerVulnerabilityAssessment or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.ServerVulnerabilityAssessment + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerVulnerabilityAssessment] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerVulnerabilityAssessment] - _json = self._serialize.body(parameters, 'ServerVulnerabilityAssessment') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerVulnerabilityAssessment") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -324,7 +388,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -332,10 +397,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201]: @@ -343,18 +407,17 @@ def create_or_update( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize('ServerVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("ServerVulnerabilityAssessment", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('ServerVulnerabilityAssessment', pipeline_response) + deserialized = self._deserialize("ServerVulnerabilityAssessment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -367,39 +430,35 @@ def delete( # pylint: disable=inconsistent-return-statements """Removes the server's vulnerability assessment. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param server_name: The name of the server for which the vulnerability assessment is defined. + Required. :type server_name: str - :param vulnerability_assessment_name: The name of the vulnerability assessment. + :param vulnerability_assessment_name: The name of the vulnerability assessment. "default" + Required. :type vulnerability_assessment_name: str or ~azure.mgmt.sql.models.VulnerabilityAssessmentName - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, vulnerability_assessment_name=vulnerability_assessment_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata['url'], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -407,10 +466,9 @@ def delete( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -420,52 +478,43 @@ def delete( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore - + delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.ServerVulnerabilityAssessmentListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.ServerVulnerabilityAssessment"]: """Lists the vulnerability assessment policies associated with a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerVulnerabilityAssessmentListResult or the - result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerVulnerabilityAssessmentListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServerVulnerabilityAssessment or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerVulnerabilityAssessment] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerVulnerabilityAssessmentListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerVulnerabilityAssessmentListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -473,16 +522,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -498,10 +538,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -511,8 +549,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/vulnerabilityAssessments"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_servers_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_servers_operations.py index f761b79646198..71e971415be32 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_servers_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_servers_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,334 +26,260 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_resource_group_request( - resource_group_name: str, - subscription_id: str, - *, - expand: Optional[str] = None, - **kwargs: Any + resource_group_name: str, subscription_id: str, *, expand: Optional[str] = None, **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', "2021-02-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if expand is not None: - _params['$expand'] = _SERIALIZER.query("expand", expand, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$expand"] = _SERIALIZER.query("expand", expand, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - *, - expand: Optional[str] = None, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, *, expand: Optional[str] = None, **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', "2021-02-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if expand is not None: - _params['$expand'] = _SERIALIZER.query("expand", expand, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$expand"] = _SERIALIZER.query("expand", expand, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - resource_group_name: str, - server_name: str, - subscription_id: str, - *, - json: Optional[_models.Server] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, server_name: str, subscription_id: str, **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', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) - - -def build_delete_request_initial( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_delete_request( + resource_group_name: str, server_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') - - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) - - -def build_update_request_initial( - resource_group_name: str, - server_name: str, - subscription_id: str, - *, - json: Optional[_models.ServerUpdate] = None, - content: Any = None, - **kwargs: Any + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) + + +def build_update_request( + resource_group_name: str, server_name: str, subscription_id: str, **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', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) - - -def build_list_request( - subscription_id: str, - *, - expand: Optional[str] = None, - **kwargs: Any -) -> HttpRequest: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_list_request(subscription_id: str, *, expand: Optional[str] = None, **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', "2021-02-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/servers") path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if expand is not None: - _params['$expand'] = _SERIALIZER.query("expand", expand, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["$expand"] = _SERIALIZER.query("expand", expand, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_import_database_request_initial( - resource_group_name: str, - server_name: str, - subscription_id: str, - *, - json: Optional[_models.ImportNewDatabaseDefinition] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_import_database_request( + resource_group_name: str, server_name: str, subscription_id: str, **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', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/import") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/import", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) - - -def build_check_name_availability_request( - subscription_id: str, - *, - json: Optional[_models.CheckNameAvailabilityRequest] = None, - content: Any = None, - **kwargs: Any -) -> HttpRequest: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_check_name_availability_request(subscription_id: str, **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', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/checkNameAvailability") path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) + class ServersOperations: """ @@ -370,48 +300,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_resource_group( - self, - resource_group_name: str, - expand: Optional[str] = None, - **kwargs: Any - ) -> Iterable[_models.ServerListResult]: + self, resource_group_name: str, expand: Optional[str] = None, **kwargs: Any + ) -> Iterable["_models.Server"]: """Gets a list of servers in a resource groups. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerListResult or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Server or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.Server] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_request( resource_group_name=resource_group_name, subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.list_by_resource_group.metadata['url'], + api_version=api_version, + template_url=self.list_by_resource_group.metadata["url"], headers=_headers, params=_params, ) @@ -419,16 +341,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - expand=expand, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -444,10 +357,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -457,56 +368,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers"} # type: ignore + list_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - expand: Optional[str] = None, - **kwargs: Any + self, resource_group_name: str, server_name: str, expand: Optional[str] = None, **kwargs: Any ) -> _models.Server: """Gets a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Server, or the result of cls(response) + :return: Server or the result of cls(response) :rtype: ~azure.mgmt.sql.models.Server - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.Server] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.Server] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.get.metadata['url'], + api_version=api_version, + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -514,55 +413,54 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('Server', pipeline_response) + deserialized = self._deserialize("Server", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore def _create_or_update_initial( - self, - resource_group_name: str, - server_name: str, - parameters: _models.Server, - **kwargs: Any + self, resource_group_name: str, server_name: str, parameters: Union[_models.Server, IO], **kwargs: Any ) -> Optional[_models.Server]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.Server]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.Server]] - _json = self._serialize.body(parameters, 'Server') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "Server") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -570,10 +468,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -582,39 +479,75 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Server', pipeline_response) + deserialized = self._deserialize("Server", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('Server', pipeline_response) + deserialized = self._deserialize("Server", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, parameters: _models.Server, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.Server]: """Creates or updates a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param parameters: The requested server resource state. + :param parameters: The requested server resource state. Required. :type parameters: ~azure.mgmt.sql.models.Server - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 Server or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.Server] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.Server]: + """Creates or updates a server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The requested server resource state. Required. + :type parameters: IO + :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 @@ -625,20 +558,47 @@ def begin_create_or_update( Retry-After header is present. :return: An instance of LROPoller that returns either Server or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.Server] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, resource_group_name: str, server_name: str, parameters: Union[_models.Server, IO], **kwargs: Any + ) -> LROPoller[_models.Server]: + """Creates or updates a server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The requested server resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.Server 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. + :return: An instance of LROPoller that returns either Server or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.Server] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.Server] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.Server] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -646,64 +606,54 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('Server', pipeline_response) + deserialized = self._deserialize("Server", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -711,10 +661,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -724,26 +673,17 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> LROPoller[None]: + def begin_delete(self, resource_group_name: str, server_name: str, **kwargs: Any) -> LROPoller[None]: """Deletes a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -754,85 +694,79 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore def _update_initial( - self, - resource_group_name: str, - server_name: str, - parameters: _models.ServerUpdate, - **kwargs: Any + self, resource_group_name: str, server_name: str, parameters: Union[_models.ServerUpdate, IO], **kwargs: Any ) -> Optional[_models.Server]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.Server]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.Server]] - _json = self._serialize.body(parameters, 'ServerUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ServerUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -840,10 +774,9 @@ def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -852,36 +785,37 @@ def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Server', pipeline_response) + deserialized = self._deserialize("Server", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore - - @distributed_trace + @overload def begin_update( self, resource_group_name: str, server_name: str, parameters: _models.ServerUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.Server]: """Updates a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param parameters: The requested server resource state. + :param parameters: The requested server resource state. Required. :type parameters: ~azure.mgmt.sql.models.ServerUpdate - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -892,20 +826,82 @@ def begin_update( Retry-After header is present. :return: An instance of LROPoller that returns either Server or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.Server] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_update( + self, + resource_group_name: str, + server_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.Server]: + """Updates a server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The requested server resource state. Required. + :type parameters: IO + :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 Server or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.Server] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_update( + self, resource_group_name: str, server_name: str, parameters: Union[_models.ServerUpdate, IO], **kwargs: Any + ) -> LROPoller[_models.Server]: + """Updates a server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The requested server resource state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ServerUpdate 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. + :return: An instance of LROPoller that returns either Server or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.Server] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.Server] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.Server] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -913,76 +909,64 @@ def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('Server', pipeline_response) + deserialized = self._deserialize("Server", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}"} # type: ignore @distributed_trace - def list( - self, - expand: Optional[str] = None, - **kwargs: Any - ) -> Iterable[_models.ServerListResult]: + def list(self, expand: Optional[str] = None, **kwargs: Any) -> Iterable["_models.Server"]: """Gets a list of all servers in the subscription. :param expand: The child resources to include in the response. Default value is None. :type expand: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServerListResult or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServerListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Server or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.Server] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServerListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServerListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_request( subscription_id=self._config.subscription_id, - api_version=api_version, expand=expand, - template_url=self.list.metadata['url'], + api_version=api_version, + template_url=self.list.metadata["url"], headers=_headers, params=_params, ) @@ -990,15 +974,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_request( - subscription_id=self._config.subscription_id, - api_version=api_version, - expand=expand, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1014,10 +990,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1027,41 +1001,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/servers"} # type: ignore + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/servers"} # type: ignore def _import_database_initial( self, resource_group_name: str, server_name: str, - parameters: _models.ImportNewDatabaseDefinition, + parameters: Union[_models.ImportNewDatabaseDefinition, IO], **kwargs: Any ) -> Optional[_models.ImportExportOperationResult]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.ImportExportOperationResult]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.ImportExportOperationResult]] - _json = self._serialize.body(parameters, 'ImportNewDatabaseDefinition') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "ImportNewDatabaseDefinition") - request = build_import_database_request_initial( + request = build_import_database_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._import_database_initial.metadata['url'], + content=_content, + template_url=self._import_database_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1069,10 +1046,9 @@ def _import_database_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1081,36 +1057,37 @@ def _import_database_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('ImportExportOperationResult', pipeline_response) + deserialized = self._deserialize("ImportExportOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _import_database_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/import"} # type: ignore + _import_database_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/import"} # type: ignore - - @distributed_trace + @overload def begin_import_database( self, resource_group_name: str, server_name: str, parameters: _models.ImportNewDatabaseDefinition, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.ImportExportOperationResult]: """Imports a bacpac into a new database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param parameters: The database import request parameters. + :param parameters: The database import request parameters. Required. :type parameters: ~azure.mgmt.sql.models.ImportNewDatabaseDefinition - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -1122,20 +1099,88 @@ def begin_import_database( :return: An instance of LROPoller that returns either ImportExportOperationResult or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_import_database( + self, + resource_group_name: str, + server_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.ImportExportOperationResult]: + """Imports a bacpac into a new database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The database import request parameters. Required. + :type parameters: IO + :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 ImportExportOperationResult or the result + of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_import_database( + self, + resource_group_name: str, + server_name: str, + parameters: Union[_models.ImportNewDatabaseDefinition, IO], + **kwargs: Any + ) -> LROPoller[_models.ImportExportOperationResult]: + """Imports a bacpac into a new database. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The database import request parameters. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.ImportNewDatabaseDefinition 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. + :return: An instance of LROPoller that returns either ImportExportOperationResult or the result + of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.ImportExportOperationResult] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.ImportExportOperationResult] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.ImportExportOperationResult] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._import_database_initial( # type: ignore resource_group_name=resource_group_name, @@ -1143,78 +1188,112 @@ def begin_import_database( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('ImportExportOperationResult', pipeline_response) + deserialized = self._deserialize("ImportExportOperationResult", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_import_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/import"} # type: ignore + begin_import_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/import"} # type: ignore - @distributed_trace + @overload def check_name_availability( - self, - parameters: _models.CheckNameAvailabilityRequest, - **kwargs: Any + self, parameters: _models.CheckNameAvailabilityRequest, *, content_type: str = "application/json", **kwargs: Any ) -> _models.CheckNameAvailabilityResponse: """Determines whether a resource can be created with the specified name. - :param parameters: The name availability request parameters. + :param parameters: The name availability request parameters. Required. :type parameters: ~azure.mgmt.sql.models.CheckNameAvailabilityRequest - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: CheckNameAvailabilityResponse, or the result of cls(response) + :return: CheckNameAvailabilityResponse or the result of cls(response) :rtype: ~azure.mgmt.sql.models.CheckNameAvailabilityResponse - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + + @overload + def check_name_availability( + self, parameters: IO, *, content_type: str = "application/json", **kwargs: Any + ) -> _models.CheckNameAvailabilityResponse: + """Determines whether a resource can be created with the specified name. + + :param parameters: The name availability request parameters. Required. + :type parameters: IO + :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: CheckNameAvailabilityResponse or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.CheckNameAvailabilityResponse + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def check_name_availability( + self, parameters: Union[_models.CheckNameAvailabilityRequest, IO], **kwargs: Any + ) -> _models.CheckNameAvailabilityResponse: + """Determines whether a resource can be created with the specified name. + + :param parameters: The name availability request parameters. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.CheckNameAvailabilityRequest 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 + :return: CheckNameAvailabilityResponse or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.CheckNameAvailabilityResponse + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.CheckNameAvailabilityResponse] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.CheckNameAvailabilityResponse] - _json = self._serialize.body(parameters, 'CheckNameAvailabilityRequest') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "CheckNameAvailabilityRequest") request = build_check_name_availability_request( subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self.check_name_availability.metadata['url'], + content=_content, + template_url=self.check_name_availability.metadata["url"], headers=_headers, params=_params, ) @@ -1222,22 +1301,20 @@ def check_name_availability( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('CheckNameAvailabilityResponse', pipeline_response) + deserialized = self._deserialize("CheckNameAvailabilityResponse", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - check_name_availability.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/checkNameAvailability"} # type: ignore - + check_name_availability.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/checkNameAvailability"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_service_objectives_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_service_objectives_operations.py index 32ea40c37cfb5..b0edc8b31e5ee 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_service_objectives_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_service_objectives_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,87 +24,78 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( - subscription_id: str, - resource_group_name: str, - server_name: str, - service_objective_name: str, - **kwargs: Any + resource_group_name: str, server_name: str, service_objective_name: str, subscription_id: str, **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', "2014-04-01")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/serviceObjectives/{serviceObjectiveName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/serviceObjectives/{serviceObjectiveName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "serviceObjectiveName": _SERIALIZER.url("service_objective_name", service_objective_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "serviceObjectiveName": _SERIALIZER.url("service_objective_name", service_objective_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_server_request( - subscription_id: str, - resource_group_name: str, - server_name: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2014-04-01")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2014-04-01")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/serviceObjectives") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/serviceObjectives", + ) # pylint: disable=line-too-long path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class ServiceObjectivesOperations: """ @@ -121,51 +116,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - service_objective_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, service_objective_name: str, **kwargs: Any ) -> _models.ServiceObjective: """Gets a database service objective. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param service_objective_name: The name of the service objective to retrieve. + :param service_objective_name: The name of the service objective to retrieve. Required. :type service_objective_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: ServiceObjective, or the result of cls(response) + :return: ServiceObjective or the result of cls(response) :rtype: ~azure.mgmt.sql.models.ServiceObjective - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServiceObjective] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceObjective] - request = build_get_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, service_objective_name=service_objective_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -173,68 +157,58 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('ServiceObjective', pipeline_response) + deserialized = self._deserialize("ServiceObjective", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/serviceObjectives/{serviceObjectiveName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/serviceObjectives/{serviceObjectiveName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.ServiceObjectiveListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.ServiceObjective"]: """Returns database service objectives. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2014-04-01". Note that overriding this - default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either ServiceObjectiveListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServiceObjectiveListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either ServiceObjective or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.ServiceObjective] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2014-04-01")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.ServiceObjectiveListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceObjectiveListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( - subscription_id=self._config.subscription_id, resource_group_name=resource_group_name, server_name=server_name, + subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -242,16 +216,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - subscription_id=self._config.subscription_id, - resource_group_name=resource_group_name, - server_name=server_name, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -267,10 +232,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -280,8 +243,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/serviceObjectives"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/serviceObjectives"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sql_agent_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sql_agent_operations.py index 36e27b79abafa..e325bb7bd7a87 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sql_agent_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sql_agent_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse from azure.core.rest import HttpRequest @@ -19,93 +23,80 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/sqlAgent/current") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/sqlAgent/current", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( - resource_group_name: str, - managed_instance_name: str, - subscription_id: str, - *, - json: Optional[_models.SqlAgentConfiguration] = None, - content: Any = None, - **kwargs: Any + resource_group_name: str, managed_instance_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/sqlAgent/current") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/sqlAgent/current", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "managedInstanceName": _SERIALIZER.url("managed_instance_name", managed_instance_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + class SqlAgentOperations: """ @@ -126,47 +117,35 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace - def get( - self, - resource_group_name: str, - managed_instance_name: str, - **kwargs: Any - ) -> _models.SqlAgentConfiguration: + def get(self, resource_group_name: str, managed_instance_name: str, **kwargs: Any) -> _models.SqlAgentConfiguration: """Gets current instance sql agent configuration. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SqlAgentConfiguration, or the result of cls(response) + :return: SqlAgentConfiguration or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SqlAgentConfiguration - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SqlAgentConfiguration] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SqlAgentConfiguration] - request = build_get_request( resource_group_name=resource_group_name, managed_instance_name=managed_instance_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -174,64 +153,122 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SqlAgentConfiguration', pipeline_response) + deserialized = self._deserialize("SqlAgentConfiguration", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/sqlAgent/current"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/sqlAgent/current"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, managed_instance_name: str, parameters: _models.SqlAgentConfiguration, + *, + content_type: str = "application/json", **kwargs: Any ) -> _models.SqlAgentConfiguration: """Puts new sql agent configuration to instance. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param managed_instance_name: The name of the managed instance. + :param managed_instance_name: The name of the managed instance. Required. :type managed_instance_name: str - :param parameters: + :param parameters: Required. :type parameters: ~azure.mgmt.sql.models.SqlAgentConfiguration - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: SqlAgentConfiguration or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.SqlAgentConfiguration + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.SqlAgentConfiguration: + """Puts new sql agent configuration to instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param parameters: Required. + :type parameters: IO + :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: SqlAgentConfiguration or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.SqlAgentConfiguration + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + managed_instance_name: str, + parameters: Union[_models.SqlAgentConfiguration, IO], + **kwargs: Any + ) -> _models.SqlAgentConfiguration: + """Puts new sql agent configuration to instance. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param managed_instance_name: The name of the managed instance. Required. + :type managed_instance_name: str + :param parameters: Is either a model type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.SqlAgentConfiguration 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 - :return: SqlAgentConfiguration, or the result of cls(response) + :return: SqlAgentConfiguration or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SqlAgentConfiguration - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.SqlAgentConfiguration] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.SqlAgentConfiguration] - _json = self._serialize.body(parameters, 'SqlAgentConfiguration') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SqlAgentConfiguration") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -240,7 +277,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -248,22 +286,20 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SqlAgentConfiguration', pipeline_response) + deserialized = self._deserialize("SqlAgentConfiguration", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/sqlAgent/current"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/sqlAgent/current"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_subscription_usages_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_subscription_usages_operations.py index 5f3a5adb9eebb..4db1047485029 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_subscription_usages_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_subscription_usages_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,83 +24,71 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False -def build_list_by_location_request( - location_name: str, - subscription_id: str, - **kwargs: Any -) -> HttpRequest: + +def build_list_by_location_request(location_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/usages") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/usages" + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_get_request( - location_name: str, - usage_name: str, - subscription_id: str, - **kwargs: Any -) -> HttpRequest: + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_get_request(location_name: str, usage_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/usages/{usageName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/usages/{usageName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "usageName": _SERIALIZER.url("usage_name", usage_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "usageName": _SERIALIZER.url("usage_name", usage_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class SubscriptionUsagesOperations: """ @@ -117,44 +109,34 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace - def list_by_location( - self, - location_name: str, - **kwargs: Any - ) -> Iterable[_models.SubscriptionUsageListResult]: + def list_by_location(self, location_name: str, **kwargs: Any) -> Iterable["_models.SubscriptionUsage"]: """Gets all subscription usage metrics in a given location. - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SubscriptionUsageListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SubscriptionUsageListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SubscriptionUsage or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SubscriptionUsage] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SubscriptionUsageListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SubscriptionUsageListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_location_request( location_name=location_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_location.metadata['url'], + template_url=self.list_by_location.metadata["url"], headers=_headers, params=_params, ) @@ -162,15 +144,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_location_request( - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -186,10 +160,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -199,51 +171,38 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/usages"} # type: ignore + list_by_location.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/usages"} # type: ignore @distributed_trace - def get( - self, - location_name: str, - usage_name: str, - **kwargs: Any - ) -> _models.SubscriptionUsage: + def get(self, location_name: str, usage_name: str, **kwargs: Any) -> _models.SubscriptionUsage: """Gets a subscription usage metric. - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :param usage_name: Name of usage metric to return. + :param usage_name: Name of usage metric to return. Required. :type usage_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SubscriptionUsage, or the result of cls(response) + :return: SubscriptionUsage or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SubscriptionUsage - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SubscriptionUsage] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SubscriptionUsage] - request = build_get_request( location_name=location_name, usage_name=usage_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -251,22 +210,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SubscriptionUsage', pipeline_response) + deserialized = self._deserialize("SubscriptionUsage", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/usages/{usageName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/usages/{usageName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sync_agents_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sync_agents_operations.py index 693acedb11d5f..942859ba4289f 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sync_agents_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sync_agents_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,244 +26,203 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( - resource_group_name: str, - server_name: str, - sync_agent_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, sync_agent_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "syncAgentName": _SERIALIZER.url("sync_agent_name", sync_agent_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "syncAgentName": _SERIALIZER.url("sync_agent_name", sync_agent_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - resource_group_name: str, - server_name: str, - sync_agent_name: str, - subscription_id: str, - *, - json: Optional[_models.SyncAgent] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, server_name: str, sync_agent_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "syncAgentName": _SERIALIZER.url("sync_agent_name", sync_agent_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "syncAgentName": _SERIALIZER.url("sync_agent_name", sync_agent_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) - - -def build_delete_request_initial( - resource_group_name: str, - server_name: str, - sync_agent_name: str, - subscription_id: str, - **kwargs: Any + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_delete_request( + resource_group_name: str, server_name: str, sync_agent_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "syncAgentName": _SERIALIZER.url("sync_agent_name", sync_agent_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "syncAgentName": _SERIALIZER.url("sync_agent_name", sync_agent_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_generate_key_request( - resource_group_name: str, - server_name: str, - sync_agent_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, sync_agent_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}/generateKey") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}/generateKey", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "syncAgentName": _SERIALIZER.url("sync_agent_name", sync_agent_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "syncAgentName": _SERIALIZER.url("sync_agent_name", sync_agent_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) def build_list_linked_databases_request( - resource_group_name: str, - server_name: str, - sync_agent_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, sync_agent_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}/linkedDatabases") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}/linkedDatabases", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "syncAgentName": _SERIALIZER.url("sync_agent_name", sync_agent_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "syncAgentName": _SERIALIZER.url("sync_agent_name", sync_agent_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class SyncAgentsOperations: """ @@ -280,51 +243,38 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace - def get( - self, - resource_group_name: str, - server_name: str, - sync_agent_name: str, - **kwargs: Any - ) -> _models.SyncAgent: + def get(self, resource_group_name: str, server_name: str, sync_agent_name: str, **kwargs: Any) -> _models.SyncAgent: """Gets a sync agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server on which the sync agent is hosted. + :param server_name: The name of the server on which the sync agent is hosted. Required. :type server_name: str - :param sync_agent_name: The name of the sync agent. + :param sync_agent_name: The name of the sync agent. Required. :type sync_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SyncAgent, or the result of cls(response) + :return: SyncAgent or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SyncAgent - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncAgent] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncAgent] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, sync_agent_name=sync_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -332,49 +282,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SyncAgent', pipeline_response) + deserialized = self._deserialize("SyncAgent", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, sync_agent_name: str, - parameters: _models.SyncAgent, + parameters: Union[_models.SyncAgent, IO], **kwargs: Any ) -> Optional[_models.SyncAgent]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.SyncAgent]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.SyncAgent]] - _json = self._serialize.body(parameters, 'SyncAgent') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SyncAgent") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, sync_agent_name=sync_agent_name, @@ -382,7 +334,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -390,10 +343,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -402,42 +354,118 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('SyncAgent', pipeline_response) + deserialized = self._deserialize("SyncAgent", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('SyncAgent', pipeline_response) + deserialized = self._deserialize("SyncAgent", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, sync_agent_name: str, parameters: _models.SyncAgent, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.SyncAgent]: """Creates or updates a sync agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server on which the sync agent is hosted. + :param server_name: The name of the server on which the sync agent is hosted. Required. :type server_name: str - :param sync_agent_name: The name of the sync agent. + :param sync_agent_name: The name of the sync agent. Required. :type sync_agent_name: str - :param parameters: The requested sync agent resource state. + :param parameters: The requested sync agent resource state. Required. :type parameters: ~azure.mgmt.sql.models.SyncAgent - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 SyncAgent or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.SyncAgent] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + sync_agent_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.SyncAgent]: + """Creates or updates a sync agent. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server on which the sync agent is hosted. Required. + :type server_name: str + :param sync_agent_name: The name of the sync agent. Required. + :type sync_agent_name: str + :param parameters: The requested sync agent resource state. Required. + :type parameters: IO + :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 SyncAgent or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.SyncAgent] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + sync_agent_name: str, + parameters: Union[_models.SyncAgent, IO], + **kwargs: Any + ) -> LROPoller[_models.SyncAgent]: + """Creates or updates a sync agent. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server on which the sync agent is hosted. Required. + :type server_name: str + :param sync_agent_name: The name of the sync agent. Required. + :type sync_agent_name: str + :param parameters: The requested sync agent resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.SyncAgent 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 @@ -448,20 +476,17 @@ def begin_create_or_update( Retry-After header is present. :return: An instance of LROPoller that returns either SyncAgent or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.SyncAgent] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncAgent] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncAgent] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -470,66 +495,55 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('SyncAgent', pipeline_response) + deserialized = self._deserialize("SyncAgent", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - sync_agent_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, sync_agent_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, sync_agent_name=sync_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -537,10 +551,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -550,29 +563,21 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - sync_agent_name: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, server_name: str, sync_agent_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes a sync agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server on which the sync agent is hosted. + :param server_name: The name of the server on which the sync agent is hosted. Required. :type server_name: str - :param sync_agent_name: The name of the sync agent. + :param sync_agent_name: The name of the sync agent. Required. :type sync_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -583,98 +588,84 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, sync_agent_name=sync_agent_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.SyncAgentListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.SyncAgent"]: """Lists sync agents in a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server on which the sync agent is hosted. + :param server_name: The name of the server on which the sync agent is hosted. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SyncAgentListResult or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SyncAgentListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SyncAgent or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SyncAgent] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncAgentListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncAgentListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -682,16 +673,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -707,10 +689,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -720,56 +700,44 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents"} # type: ignore @distributed_trace def generate_key( - self, - resource_group_name: str, - server_name: str, - sync_agent_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, sync_agent_name: str, **kwargs: Any ) -> _models.SyncAgentKeyProperties: """Generates a sync agent key. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server on which the sync agent is hosted. + :param server_name: The name of the server on which the sync agent is hosted. Required. :type server_name: str - :param sync_agent_name: The name of the sync agent. + :param sync_agent_name: The name of the sync agent. Required. :type sync_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SyncAgentKeyProperties, or the result of cls(response) + :return: SyncAgentKeyProperties or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SyncAgentKeyProperties - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncAgentKeyProperties] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncAgentKeyProperties] - request = build_generate_key_request( resource_group_name=resource_group_name, server_name=server_name, sync_agent_name=sync_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.generate_key.metadata['url'], + template_url=self.generate_key.metadata["url"], headers=_headers, params=_params, ) @@ -777,72 +745,62 @@ def generate_key( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SyncAgentKeyProperties', pipeline_response) + deserialized = self._deserialize("SyncAgentKeyProperties", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - generate_key.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}/generateKey"} # type: ignore - + generate_key.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}/generateKey"} # type: ignore @distributed_trace def list_linked_databases( - self, - resource_group_name: str, - server_name: str, - sync_agent_name: str, - **kwargs: Any - ) -> Iterable[_models.SyncAgentLinkedDatabaseListResult]: + self, resource_group_name: str, server_name: str, sync_agent_name: str, **kwargs: Any + ) -> Iterable["_models.SyncAgentLinkedDatabase"]: """Lists databases linked to a sync agent. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server on which the sync agent is hosted. + :param server_name: The name of the server on which the sync agent is hosted. Required. :type server_name: str - :param sync_agent_name: The name of the sync agent. + :param sync_agent_name: The name of the sync agent. Required. :type sync_agent_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SyncAgentLinkedDatabaseListResult or the result of + :return: An iterator like instance of either SyncAgentLinkedDatabase or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SyncAgentLinkedDatabaseListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SyncAgentLinkedDatabase] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncAgentLinkedDatabaseListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncAgentLinkedDatabaseListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_linked_databases_request( resource_group_name=resource_group_name, server_name=server_name, sync_agent_name=sync_agent_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_linked_databases.metadata['url'], + template_url=self.list_linked_databases.metadata["url"], headers=_headers, params=_params, ) @@ -850,17 +808,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_linked_databases_request( - resource_group_name=resource_group_name, - server_name=server_name, - sync_agent_name=sync_agent_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -876,10 +824,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -889,8 +835,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_linked_databases.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}/linkedDatabases"} # type: ignore + list_linked_databases.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/syncAgents/{syncAgentName}/linkedDatabases"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sync_groups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sync_groups_operations.py index e2a288a60c008..bbaaace58a5f2 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sync_groups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sync_groups_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,49 +26,45 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False -def build_list_sync_database_ids_request( - location_name: str, - subscription_id: str, - **kwargs: Any -) -> HttpRequest: + +def build_list_sync_database_ids_request(location_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/syncDatabaseIds") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/syncDatabaseIds", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_refresh_hub_schema_request_initial( +def build_refresh_hub_schema_request( resource_group_name: str, server_name: str, database_name: str, @@ -74,28 +74,26 @@ def build_refresh_hub_schema_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/refreshHubSchema") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/refreshHubSchema", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) def build_list_hub_schemas_request( @@ -109,34 +107,31 @@ def build_list_hub_schemas_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/hubSchemas") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/hubSchemas", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_logs_request( @@ -155,39 +150,38 @@ def build_list_logs_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/logs") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/logs", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['startTime'] = _SERIALIZER.query("start_time", start_time, 'str') - _params['endTime'] = _SERIALIZER.query("end_time", end_time, 'str') - _params['type'] = _SERIALIZER.query("type", type, 'str') + _params["startTime"] = _SERIALIZER.query("start_time", start_time, "str") + _params["endTime"] = _SERIALIZER.query("end_time", end_time, "str") + _params["type"] = _SERIALIZER.query("type", type, "str") if continuation_token_parameter is not None: - _params['continuationToken'] = _SERIALIZER.query("continuation_token_parameter", continuation_token_parameter, 'str') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["continuationToken"] = _SERIALIZER.query( + "continuation_token_parameter", continuation_token_parameter, "str" + ) + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_cancel_sync_request( @@ -200,28 +194,26 @@ def build_cancel_sync_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/cancelSync") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/cancelSync", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) def build_trigger_sync_request( @@ -234,28 +226,26 @@ def build_trigger_sync_request( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/triggerSync") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/triggerSync", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) def build_get_request( @@ -269,86 +259,75 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, subscription_id: str, - *, - json: Optional[_models.SyncGroup] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_request_initial( +def build_delete_request( resource_group_name: str, server_name: str, database_name: str, @@ -358,116 +337,100 @@ def build_delete_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) -def build_update_request_initial( +def build_update_request( resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, subscription_id: str, - *, - json: Optional[_models.SyncGroup] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_database_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class SyncGroupsOperations: """ @@ -488,44 +451,35 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace - def list_sync_database_ids( - self, - location_name: str, - **kwargs: Any - ) -> Iterable[_models.SyncDatabaseIdListResult]: + def list_sync_database_ids(self, location_name: str, **kwargs: Any) -> Iterable["_models.SyncDatabaseIdProperties"]: """Gets a collection of sync database ids. - :param location_name: The name of the region where the resource is located. + :param location_name: The name of the region where the resource is located. Required. :type location_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SyncDatabaseIdListResult or the result of + :return: An iterator like instance of either SyncDatabaseIdProperties or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SyncDatabaseIdListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SyncDatabaseIdProperties] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncDatabaseIdListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncDatabaseIdListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_sync_database_ids_request( location_name=location_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_sync_database_ids.metadata['url'], + template_url=self.list_sync_database_ids.metadata["url"], headers=_headers, params=_params, ) @@ -533,15 +487,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_sync_database_ids_request( - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -557,10 +503,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -570,40 +514,30 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_sync_database_ids.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/syncDatabaseIds"} # type: ignore + list_sync_database_ids.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/syncDatabaseIds"} # type: ignore def _refresh_hub_schema_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_refresh_hub_schema_request_initial( + request = build_refresh_hub_schema_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, sync_group_name=sync_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._refresh_hub_schema_initial.metadata['url'], + template_url=self._refresh_hub_schema_initial.metadata["url"], headers=_headers, params=_params, ) @@ -611,10 +545,9 @@ def _refresh_hub_schema_initial( # pylint: disable=inconsistent-return-statemen request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -624,32 +557,23 @@ def _refresh_hub_schema_initial( # pylint: disable=inconsistent-return-statemen if cls: return cls(pipeline_response, None, {}) - _refresh_hub_schema_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/refreshHubSchema"} # type: ignore - + _refresh_hub_schema_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/refreshHubSchema"} # type: ignore @distributed_trace - def begin_refresh_hub_schema( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any + def begin_refresh_hub_schema( + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any ) -> LROPoller[None]: """Refreshes a hub database schema. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -660,19 +584,16 @@ def begin_refresh_hub_schema( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._refresh_hub_schema_initial( # type: ignore resource_group_name=resource_group_name, @@ -680,80 +601,67 @@ def begin_refresh_hub_schema( # pylint: disable=inconsistent-return-statements database_name=database_name, sync_group_name=sync_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_refresh_hub_schema.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/refreshHubSchema"} # type: ignore + begin_refresh_hub_schema.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/refreshHubSchema"} # type: ignore @distributed_trace def list_hub_schemas( - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any - ) -> Iterable[_models.SyncFullSchemaPropertiesListResult]: + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any + ) -> Iterable["_models.SyncFullSchemaProperties"]: """Gets a collection of hub database schemas. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SyncFullSchemaPropertiesListResult or the result - of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SyncFullSchemaPropertiesListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SyncFullSchemaProperties or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SyncFullSchemaProperties] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncFullSchemaPropertiesListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncFullSchemaPropertiesListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_hub_schemas_request( resource_group_name=resource_group_name, server_name=server_name, @@ -761,7 +669,7 @@ def prepare_request(next_link=None): sync_group_name=sync_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_hub_schemas.metadata['url'], + template_url=self.list_hub_schemas.metadata["url"], headers=_headers, params=_params, ) @@ -769,18 +677,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_hub_schemas_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - sync_group_name=sync_group_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -796,10 +693,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -809,11 +704,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_hub_schemas.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/hubSchemas"} # type: ignore + list_hub_schemas.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/hubSchemas"} # type: ignore @distributed_trace def list_logs( @@ -827,61 +720,58 @@ def list_logs( type: Union[str, "_models.SyncGroupsType"], continuation_token_parameter: Optional[str] = None, **kwargs: Any - ) -> Iterable[_models.SyncGroupLogListResult]: + ) -> Iterable["_models.SyncGroupLogProperties"]: """Gets a collection of sync group logs. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :param start_time: Get logs generated after this time. + :param start_time: Get logs generated after this time. Required. :type start_time: str - :param end_time: Get logs generated before this time. + :param end_time: Get logs generated before this time. Required. :type end_time: str - :param type: The types of logs to retrieve. + :param type: The types of logs to retrieve. Known values are: "All", "Error", "Warning", and + "Success". Required. :type type: str or ~azure.mgmt.sql.models.SyncGroupsType :param continuation_token_parameter: The continuation token for this operation. Default value is None. :type continuation_token_parameter: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SyncGroupLogListResult or the result of + :return: An iterator like instance of either SyncGroupLogProperties or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SyncGroupLogListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SyncGroupLogProperties] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncGroupLogListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncGroupLogListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_logs_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, sync_group_name=sync_group_name, subscription_id=self._config.subscription_id, - api_version=api_version, start_time=start_time, end_time=end_time, type=type, continuation_token_parameter=continuation_token_parameter, - template_url=self.list_logs.metadata['url'], + api_version=api_version, + template_url=self.list_logs.metadata["url"], headers=_headers, params=_params, ) @@ -889,22 +779,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_logs_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - sync_group_name=sync_group_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - start_time=start_time, - end_time=end_time, - type=type, - continuation_token_parameter=continuation_token_parameter, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -920,10 +795,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -933,52 +806,39 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_logs.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/logs"} # type: ignore + list_logs.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/logs"} # type: ignore @distributed_trace def cancel_sync( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any ) -> None: """Cancels a sync group synchronization. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_cancel_sync_request( resource_group_name=resource_group_name, server_name=server_name, @@ -986,7 +846,7 @@ def cancel_sync( # pylint: disable=inconsistent-return-statements sync_group_name=sync_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.cancel_sync.metadata['url'], + template_url=self.cancel_sync.metadata["url"], headers=_headers, params=_params, ) @@ -994,10 +854,9 @@ def cancel_sync( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -1007,49 +866,37 @@ def cancel_sync( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - cancel_sync.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/cancelSync"} # type: ignore - + cancel_sync.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/cancelSync"} # type: ignore @distributed_trace def trigger_sync( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any ) -> None: """Triggers a sync group synchronization. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) + :return: None or the result of cls(response) :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - request = build_trigger_sync_request( resource_group_name=resource_group_name, server_name=server_name, @@ -1057,7 +904,7 @@ def trigger_sync( # pylint: disable=inconsistent-return-statements sync_group_name=sync_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.trigger_sync.metadata['url'], + template_url=self.trigger_sync.metadata["url"], headers=_headers, params=_params, ) @@ -1065,10 +912,9 @@ def trigger_sync( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: @@ -1078,49 +924,37 @@ def trigger_sync( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - trigger_sync.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/triggerSync"} # type: ignore - + trigger_sync.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/triggerSync"} # type: ignore @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any ) -> _models.SyncGroup: """Gets a sync group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SyncGroup, or the result of cls(response) + :return: SyncGroup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SyncGroup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncGroup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncGroup] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -1128,7 +962,7 @@ def get( sync_group_name=sync_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -1136,25 +970,23 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SyncGroup', pipeline_response) + deserialized = self._deserialize("SyncGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore def _create_or_update_initial( self, @@ -1162,24 +994,28 @@ def _create_or_update_initial( server_name: str, database_name: str, sync_group_name: str, - parameters: _models.SyncGroup, + parameters: Union[_models.SyncGroup, IO], **kwargs: Any ) -> Optional[_models.SyncGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.SyncGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.SyncGroup]] - _json = self._serialize.body(parameters, 'SyncGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SyncGroup") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -1188,7 +1024,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1196,10 +1033,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -1208,20 +1044,19 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('SyncGroup', pipeline_response) + deserialized = self._deserialize("SyncGroup", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('SyncGroup', pipeline_response) + deserialized = self._deserialize("SyncGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, @@ -1229,24 +1064,26 @@ def begin_create_or_update( database_name: str, sync_group_name: str, parameters: _models.SyncGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.SyncGroup]: """Creates or updates a sync group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :param parameters: The requested sync group resource state. + :param parameters: The requested sync group resource state. Required. :type parameters: ~azure.mgmt.sql.models.SyncGroup - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -1257,20 +1094,98 @@ def begin_create_or_update( Retry-After header is present. :return: An instance of LROPoller that returns either SyncGroup or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.SyncGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + sync_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.SyncGroup]: + """Creates or updates a sync group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database on which the sync group is hosted. Required. + :type database_name: str + :param sync_group_name: The name of the sync group. Required. + :type sync_group_name: str + :param parameters: The requested sync group resource state. Required. + :type parameters: IO + :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 SyncGroup or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.SyncGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + sync_group_name: str, + parameters: Union[_models.SyncGroup, IO], + **kwargs: Any + ) -> LROPoller[_models.SyncGroup]: + """Creates or updates a sync group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database on which the sync group is hosted. Required. + :type database_name: str + :param sync_group_name: The name of the sync group. Required. + :type sync_group_name: str + :param parameters: The requested sync group resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.SyncGroup 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. + :return: An instance of LROPoller that returns either SyncGroup or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.SyncGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -1280,68 +1195,56 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('SyncGroup', pipeline_response) + deserialized = self._deserialize("SyncGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, sync_group_name=sync_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1349,10 +1252,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -1362,32 +1264,23 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes a sync group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1398,19 +1291,16 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, @@ -1418,37 +1308,33 @@ def begin_delete( # pylint: disable=inconsistent-return-statements database_name=database_name, sync_group_name=sync_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore def _update_initial( self, @@ -1456,24 +1342,28 @@ def _update_initial( server_name: str, database_name: str, sync_group_name: str, - parameters: _models.SyncGroup, + parameters: Union[_models.SyncGroup, IO], **kwargs: Any ) -> Optional[_models.SyncGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.SyncGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.SyncGroup]] - _json = self._serialize.body(parameters, 'SyncGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SyncGroup") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -1482,7 +1372,8 @@ def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1490,10 +1381,9 @@ def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1502,17 +1392,16 @@ def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('SyncGroup', pipeline_response) + deserialized = self._deserialize("SyncGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore - - @distributed_trace + @overload def begin_update( self, resource_group_name: str, @@ -1520,24 +1409,107 @@ def begin_update( database_name: str, sync_group_name: str, parameters: _models.SyncGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.SyncGroup]: """Updates a sync group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :param parameters: The requested sync group resource state. + :param parameters: The requested sync group resource state. Required. :type parameters: ~azure.mgmt.sql.models.SyncGroup - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 SyncGroup or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.SyncGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + sync_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.SyncGroup]: + """Updates a sync group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database on which the sync group is hosted. Required. + :type database_name: str + :param sync_group_name: The name of the sync group. Required. + :type sync_group_name: str + :param parameters: The requested sync group resource state. Required. + :type parameters: IO + :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 SyncGroup or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.SyncGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + sync_group_name: str, + parameters: Union[_models.SyncGroup, IO], + **kwargs: Any + ) -> LROPoller[_models.SyncGroup]: + """Updates a sync group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database on which the sync group is hosted. Required. + :type database_name: str + :param sync_group_name: The name of the sync group. Required. + :type sync_group_name: str + :param parameters: The requested sync group resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.SyncGroup 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 @@ -1548,20 +1520,17 @@ def begin_update( Retry-After header is present. :return: An instance of LROPoller that returns either SyncGroup or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.SyncGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -1571,85 +1540,73 @@ def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('SyncGroup', pipeline_response) + deserialized = self._deserialize("SyncGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.SyncGroupListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.SyncGroup"]: """Lists sync groups under a hub database. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SyncGroupListResult or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SyncGroupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SyncGroup or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SyncGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncGroupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncGroupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -1657,17 +1614,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1683,10 +1630,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1696,8 +1641,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sync_members_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sync_members_operations.py index 5f521d38e0e7e..09aa919c6ae5e 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sync_members_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_sync_members_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -41,89 +48,78 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, 'str'), - "syncMemberName": _SERIALIZER.url("sync_member_name", sync_member_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, "str"), + "syncMemberName": _SERIALIZER.url("sync_member_name", sync_member_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, sync_member_name: str, subscription_id: str, - *, - json: Optional[_models.SyncMember] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, 'str'), - "syncMemberName": _SERIALIZER.url("sync_member_name", sync_member_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, "str"), + "syncMemberName": _SERIALIZER.url("sync_member_name", sync_member_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_request_initial( +def build_delete_request( resource_group_name: str, server_name: str, database_name: str, @@ -134,80 +130,70 @@ def build_delete_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, 'str'), - "syncMemberName": _SERIALIZER.url("sync_member_name", sync_member_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, "str"), + "syncMemberName": _SERIALIZER.url("sync_member_name", sync_member_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) -def build_update_request_initial( +def build_update_request( resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, sync_member_name: str, subscription_id: str, - *, - json: Optional[_models.SyncMember] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, 'str'), - "syncMemberName": _SERIALIZER.url("sync_member_name", sync_member_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, "str"), + "syncMemberName": _SERIALIZER.url("sync_member_name", sync_member_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_sync_group_request( @@ -221,34 +207,31 @@ def build_list_by_sync_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_list_member_schemas_request( @@ -263,38 +246,35 @@ def build_list_member_schemas_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}/schemas") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}/schemas", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, 'str'), - "syncMemberName": _SERIALIZER.url("sync_member_name", sync_member_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, "str"), + "syncMemberName": _SERIALIZER.url("sync_member_name", sync_member_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_refresh_member_schema_request_initial( +def build_refresh_member_schema_request( resource_group_name: str, server_name: str, database_name: str, @@ -305,29 +285,28 @@ def build_refresh_member_schema_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}/refreshSchema") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}/refreshSchema", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, 'str'), - "syncMemberName": _SERIALIZER.url("sync_member_name", sync_member_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "syncGroupName": _SERIALIZER.url("sync_group_name", sync_group_name, "str"), + "syncMemberName": _SERIALIZER.url("sync_member_name", sync_member_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="POST", url=_url, params=_params, **kwargs) - return HttpRequest( - method="POST", - url=_url, - params=_params, - **kwargs - ) class SyncMembersOperations: """ @@ -348,7 +327,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -362,36 +340,31 @@ def get( """Gets a sync member. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. :type sync_group_name: str - :param sync_member_name: The name of the sync member. + :param sync_member_name: The name of the sync member. Required. :type sync_member_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: SyncMember, or the result of cls(response) + :return: SyncMember or the result of cls(response) :rtype: ~azure.mgmt.sql.models.SyncMember - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncMember] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncMember] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -400,7 +373,7 @@ def get( sync_member_name=sync_member_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -408,25 +381,23 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('SyncMember', pipeline_response) + deserialized = self._deserialize("SyncMember", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore def _create_or_update_initial( self, @@ -435,24 +406,28 @@ def _create_or_update_initial( database_name: str, sync_group_name: str, sync_member_name: str, - parameters: _models.SyncMember, + parameters: Union[_models.SyncMember, IO], **kwargs: Any ) -> Optional[_models.SyncMember]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.SyncMember]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.SyncMember]] - _json = self._serialize.body(parameters, 'SyncMember') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SyncMember") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -462,7 +437,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -470,10 +446,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -482,20 +457,19 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('SyncMember', pipeline_response) + deserialized = self._deserialize("SyncMember", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('SyncMember', pipeline_response) + deserialized = self._deserialize("SyncMember", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, @@ -504,26 +478,29 @@ def begin_create_or_update( sync_group_name: str, sync_member_name: str, parameters: _models.SyncMember, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.SyncMember]: """Creates or updates a sync member. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. :type sync_group_name: str - :param sync_member_name: The name of the sync member. + :param sync_member_name: The name of the sync member. Required. :type sync_member_name: str - :param parameters: The requested sync member resource state. + :param parameters: The requested sync member resource state. Required. :type parameters: ~azure.mgmt.sql.models.SyncMember - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -534,20 +511,106 @@ def begin_create_or_update( Retry-After header is present. :return: An instance of LROPoller that returns either SyncMember or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.SyncMember] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + sync_group_name: str, + sync_member_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.SyncMember]: + """Creates or updates a sync member. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database on which the sync group is hosted. Required. + :type database_name: str + :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. + :type sync_group_name: str + :param sync_member_name: The name of the sync member. Required. + :type sync_member_name: str + :param parameters: The requested sync member resource state. Required. + :type parameters: IO + :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 SyncMember or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.SyncMember] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + sync_group_name: str, + sync_member_name: str, + parameters: Union[_models.SyncMember, IO], + **kwargs: Any + ) -> LROPoller[_models.SyncMember]: + """Creates or updates a sync member. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database on which the sync group is hosted. Required. + :type database_name: str + :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. + :type sync_group_name: str + :param sync_member_name: The name of the sync member. Required. + :type sync_member_name: str + :param parameters: The requested sync member resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.SyncMember 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. + :return: An instance of LROPoller that returns either SyncMember or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.SyncMember] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncMember] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncMember] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -558,39 +621,35 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('SyncMember', pipeline_response) + deserialized = self._deserialize("SyncMember", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements self, @@ -601,19 +660,16 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements sync_member_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -621,7 +677,7 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements sync_member_name=sync_member_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -629,10 +685,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -642,11 +697,10 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements + def begin_delete( self, resource_group_name: str, server_name: str, @@ -658,19 +712,17 @@ def begin_delete( # pylint: disable=inconsistent-return-statements """Deletes a sync member. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. :type sync_group_name: str - :param sync_member_name: The name of the sync member. + :param sync_member_name: The name of the sync member. Required. :type sync_member_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -681,19 +733,16 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, @@ -702,37 +751,33 @@ def begin_delete( # pylint: disable=inconsistent-return-statements sync_group_name=sync_group_name, sync_member_name=sync_member_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore def _update_initial( self, @@ -741,24 +786,28 @@ def _update_initial( database_name: str, sync_group_name: str, sync_member_name: str, - parameters: _models.SyncMember, + parameters: Union[_models.SyncMember, IO], **kwargs: Any ) -> Optional[_models.SyncMember]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.SyncMember]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.SyncMember]] - _json = self._serialize.body(parameters, 'SyncMember') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "SyncMember") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -768,7 +817,8 @@ def _update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -776,10 +826,9 @@ def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -788,17 +837,16 @@ def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('SyncMember', pipeline_response) + deserialized = self._deserialize("SyncMember", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore - + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore - @distributed_trace + @overload def begin_update( self, resource_group_name: str, @@ -807,26 +855,29 @@ def begin_update( sync_group_name: str, sync_member_name: str, parameters: _models.SyncMember, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.SyncMember]: """Updates an existing sync member. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. :type sync_group_name: str - :param sync_member_name: The name of the sync member. + :param sync_member_name: The name of the sync member. Required. :type sync_member_name: str - :param parameters: The requested sync member resource state. + :param parameters: The requested sync member resource state. Required. :type parameters: ~azure.mgmt.sql.models.SyncMember - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -837,20 +888,106 @@ def begin_update( Retry-After header is present. :return: An instance of LROPoller that returns either SyncMember or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.SyncMember] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + sync_group_name: str, + sync_member_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.SyncMember]: + """Updates an existing sync member. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database on which the sync group is hosted. Required. + :type database_name: str + :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. + :type sync_group_name: str + :param sync_member_name: The name of the sync member. Required. + :type sync_member_name: str + :param parameters: The requested sync member resource state. Required. + :type parameters: IO + :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 SyncMember or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.SyncMember] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + sync_group_name: str, + sync_member_name: str, + parameters: Union[_models.SyncMember, IO], + **kwargs: Any + ) -> LROPoller[_models.SyncMember]: + """Updates an existing sync member. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database on which the sync group is hosted. Required. + :type database_name: str + :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. + :type sync_group_name: str + :param sync_member_name: The name of the sync member. Required. + :type sync_member_name: str + :param parameters: The requested sync member resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.SyncMember 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. + :return: An instance of LROPoller that returns either SyncMember or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.SyncMember] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncMember] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncMember] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -861,82 +998,68 @@ def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('SyncMember', pipeline_response) + deserialized = self._deserialize("SyncMember", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}"} # type: ignore @distributed_trace def list_by_sync_group( - self, - resource_group_name: str, - server_name: str, - database_name: str, - sync_group_name: str, - **kwargs: Any - ) -> Iterable[_models.SyncMemberListResult]: + self, resource_group_name: str, server_name: str, database_name: str, sync_group_name: str, **kwargs: Any + ) -> Iterable["_models.SyncMember"]: """Lists sync members in the given sync group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str - :param sync_group_name: The name of the sync group. + :param sync_group_name: The name of the sync group. Required. :type sync_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SyncMemberListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SyncMemberListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SyncMember or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SyncMember] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncMemberListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncMemberListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_sync_group_request( resource_group_name=resource_group_name, server_name=server_name, @@ -944,7 +1067,7 @@ def prepare_request(next_link=None): sync_group_name=sync_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_sync_group.metadata['url'], + template_url=self.list_by_sync_group.metadata["url"], headers=_headers, params=_params, ) @@ -952,18 +1075,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_sync_group_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - sync_group_name=sync_group_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -979,10 +1091,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -992,11 +1102,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_sync_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers"} # type: ignore + list_by_sync_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers"} # type: ignore @distributed_trace def list_member_schemas( @@ -1007,42 +1115,39 @@ def list_member_schemas( sync_group_name: str, sync_member_name: str, **kwargs: Any - ) -> Iterable[_models.SyncFullSchemaPropertiesListResult]: + ) -> Iterable["_models.SyncFullSchemaProperties"]: """Gets a sync member database schema. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. :type sync_group_name: str - :param sync_member_name: The name of the sync member. + :param sync_member_name: The name of the sync member. Required. :type sync_member_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either SyncFullSchemaPropertiesListResult or the result - of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SyncFullSchemaPropertiesListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either SyncFullSchemaProperties or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.SyncFullSchemaProperties] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.SyncFullSchemaPropertiesListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.SyncFullSchemaPropertiesListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_member_schemas_request( resource_group_name=resource_group_name, server_name=server_name, @@ -1051,7 +1156,7 @@ def prepare_request(next_link=None): sync_member_name=sync_member_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_member_schemas.metadata['url'], + template_url=self.list_member_schemas.metadata["url"], headers=_headers, params=_params, ) @@ -1059,19 +1164,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_member_schemas_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - sync_group_name=sync_group_name, - sync_member_name=sync_member_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -1087,10 +1180,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -1100,11 +1191,9 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_member_schemas.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}/schemas"} # type: ignore + list_member_schemas.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}/schemas"} # type: ignore def _refresh_member_schema_initial( # pylint: disable=inconsistent-return-statements self, @@ -1115,19 +1204,16 @@ def _refresh_member_schema_initial( # pylint: disable=inconsistent-return-state sync_member_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_refresh_member_schema_request_initial( + request = build_refresh_member_schema_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -1135,7 +1221,7 @@ def _refresh_member_schema_initial( # pylint: disable=inconsistent-return-state sync_member_name=sync_member_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._refresh_member_schema_initial.metadata['url'], + template_url=self._refresh_member_schema_initial.metadata["url"], headers=_headers, params=_params, ) @@ -1143,10 +1229,9 @@ def _refresh_member_schema_initial( # pylint: disable=inconsistent-return-state request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -1156,11 +1241,10 @@ def _refresh_member_schema_initial( # pylint: disable=inconsistent-return-state if cls: return cls(pipeline_response, None, {}) - _refresh_member_schema_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}/refreshSchema"} # type: ignore - + _refresh_member_schema_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}/refreshSchema"} # type: ignore @distributed_trace - def begin_refresh_member_schema( # pylint: disable=inconsistent-return-statements + def begin_refresh_member_schema( self, resource_group_name: str, server_name: str, @@ -1172,19 +1256,17 @@ def begin_refresh_member_schema( # pylint: disable=inconsistent-return-statemen """Refreshes a sync member database schema. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database on which the sync group is hosted. + :param database_name: The name of the database on which the sync group is hosted. Required. :type database_name: str :param sync_group_name: The name of the sync group on which the sync member is hosted. + Required. :type sync_group_name: str - :param sync_member_name: The name of the sync member. + :param sync_member_name: The name of the sync member. Required. :type sync_member_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -1195,19 +1277,16 @@ def begin_refresh_member_schema( # pylint: disable=inconsistent-return-statemen 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._refresh_member_schema_initial( # type: ignore resource_group_name=resource_group_name, @@ -1216,34 +1295,30 @@ def begin_refresh_member_schema( # pylint: disable=inconsistent-return-statemen sync_group_name=sync_group_name, sync_member_name=sync_member_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_refresh_member_schema.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}/refreshSchema"} # type: ignore + begin_refresh_member_schema.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/syncGroups/{syncGroupName}/syncMembers/{syncMemberName}/refreshSchema"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_tde_certificates_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_tde_certificates_operations.py index 38f715d6ea39d..cf26a23d0d1a9 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_tde_certificates_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_tde_certificates_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod @@ -21,53 +25,46 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False -def build_create_request_initial( - resource_group_name: str, - server_name: str, - subscription_id: str, - *, - json: Optional[_models.TdeCertificate] = None, - content: Any = None, - **kwargs: Any + +def build_create_request( + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/tdeCertificates") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/tdeCertificates", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) + class TdeCertificatesOperations: """ @@ -88,36 +85,36 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - def _create_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - parameters: _models.TdeCertificate, - **kwargs: Any + self, resource_group_name: str, server_name: str, parameters: Union[_models.TdeCertificate, IO], **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[None] - _json = self._serialize.body(parameters, 'TdeCertificate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "TdeCertificate") - request = build_create_request_initial( + request = build_create_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_initial.metadata['url'], + content=_content, + template_url=self._create_initial.metadata["url"], headers=_headers, params=_params, ) @@ -125,10 +122,9 @@ def _create_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -138,29 +134,30 @@ def _create_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _create_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/tdeCertificates"} # type: ignore - + _create_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/tdeCertificates"} # type: ignore - @distributed_trace - def begin_create( # pylint: disable=inconsistent-return-statements + @overload + def begin_create( self, resource_group_name: str, server_name: str, parameters: _models.TdeCertificate, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[None]: """Creates a TDE certificate for a given server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param parameters: The requested TDE certificate to be created or updated. + :param parameters: The requested TDE certificate to be created or updated. Required. :type parameters: ~azure.mgmt.sql.models.TdeCertificate - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 @@ -171,20 +168,82 @@ def begin_create( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create( + self, + resource_group_name: str, + server_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[None]: + """Creates a TDE certificate for a given server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The requested TDE certificate to be created or updated. Required. + :type parameters: IO + :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: + """ + + @distributed_trace + def begin_create( + self, resource_group_name: str, server_name: str, parameters: Union[_models.TdeCertificate, IO], **kwargs: Any + ) -> LROPoller[None]: + """Creates a TDE certificate for a given server. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param parameters: The requested TDE certificate to be created or updated. Is either a model + type or a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.TdeCertificate 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. + :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: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + 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] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_initial( # type: ignore resource_group_name=resource_group_name, @@ -192,34 +251,30 @@ def begin_create( # pylint: disable=inconsistent-return-statements parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_create.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/tdeCertificates"} # type: ignore + begin_create.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/tdeCertificates"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_time_zones_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_time_zones_operations.py index 61f60f2f9b5f1..f4588743310c4 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_time_zones_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_time_zones_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,83 +24,71 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False -def build_list_by_location_request( - location_name: str, - subscription_id: str, - **kwargs: Any -) -> HttpRequest: + +def build_list_by_location_request(location_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/timeZones") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/timeZones" + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_get_request( - location_name: str, - time_zone_id: str, - subscription_id: str, - **kwargs: Any -) -> HttpRequest: + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_get_request(location_name: str, time_zone_id: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/timeZones/{timeZoneId}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/timeZones/{timeZoneId}", + ) # pylint: disable=line-too-long path_format_arguments = { - "locationName": _SERIALIZER.url("location_name", location_name, 'str'), - "timeZoneId": _SERIALIZER.url("time_zone_id", time_zone_id, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "locationName": _SERIALIZER.url("location_name", location_name, "str"), + "timeZoneId": _SERIALIZER.url("time_zone_id", time_zone_id, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class TimeZonesOperations: """ @@ -117,43 +109,34 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace - def list_by_location( - self, - location_name: str, - **kwargs: Any - ) -> Iterable[_models.TimeZoneListResult]: + def list_by_location(self, location_name: str, **kwargs: Any) -> Iterable["_models.TimeZone"]: """Gets a list of managed instance time zones by location. - :param location_name: + :param location_name: Required. :type location_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either TimeZoneListResult or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.TimeZoneListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either TimeZone or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.TimeZone] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.TimeZoneListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.TimeZoneListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_location_request( location_name=location_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_location.metadata['url'], + template_url=self.list_by_location.metadata["url"], headers=_headers, params=_params, ) @@ -161,15 +144,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_location_request( - location_name=location_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -185,10 +160,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -198,51 +171,38 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/timeZones"} # type: ignore + list_by_location.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/timeZones"} # type: ignore @distributed_trace - def get( - self, - location_name: str, - time_zone_id: str, - **kwargs: Any - ) -> _models.TimeZone: + def get(self, location_name: str, time_zone_id: str, **kwargs: Any) -> _models.TimeZone: """Gets a managed instance time zone. - :param location_name: + :param location_name: Required. :type location_name: str - :param time_zone_id: + :param time_zone_id: Required. :type time_zone_id: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: TimeZone, or the result of cls(response) + :return: TimeZone or the result of cls(response) :rtype: ~azure.mgmt.sql.models.TimeZone - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.TimeZone] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.TimeZone] - request = build_get_request( location_name=location_name, time_zone_id=time_zone_id, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -250,22 +210,20 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('TimeZone', pipeline_response) + deserialized = self._deserialize("TimeZone", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/timeZones/{timeZoneId}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/timeZones/{timeZoneId}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_transparent_data_encryptions_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_transparent_data_encryptions_operations.py index 0cf7e4a430e27..2adcf894988ac 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_transparent_data_encryptions_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_transparent_data_encryptions_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -38,34 +45,31 @@ 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', "2021-02-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption/{tdeName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption/{tdeName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "tdeName": _SERIALIZER.url("tde_name", tde_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "tdeName": _SERIALIZER.url("tde_name", tde_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_create_or_update_request( @@ -74,86 +78,72 @@ def build_create_or_update_request( database_name: str, tde_name: Union[str, "_models.TransparentDataEncryptionName"], subscription_id: str, - *, - json: Optional[_models.LogicalDatabaseTransparentDataEncryption] = None, - content: Any = None, **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', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption/{tdeName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption/{tdeName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "tdeName": _SERIALIZER.url("tde_name", tde_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "tdeName": _SERIALIZER.url("tde_name", tde_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) def build_list_by_database_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2021-02-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class TransparentDataEncryptionsOperations: """ @@ -174,7 +164,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -187,35 +176,29 @@ def get( """Gets a logical database's transparent data encryption. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the logical database for which the transparent data - encryption is defined. + encryption is defined. Required. :type database_name: str - :param tde_name: The name of the transparent data encryption configuration. + :param tde_name: The name of the transparent data encryption configuration. "current" Required. :type tde_name: str or ~azure.mgmt.sql.models.TransparentDataEncryptionName - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: LogicalDatabaseTransparentDataEncryption, or the result of cls(response) + :return: LogicalDatabaseTransparentDataEncryption or the result of cls(response) :rtype: ~azure.mgmt.sql.models.LogicalDatabaseTransparentDataEncryption - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LogicalDatabaseTransparentDataEncryption] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LogicalDatabaseTransparentDataEncryption] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -223,7 +206,7 @@ def get( tde_name=tde_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -231,27 +214,25 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('LogicalDatabaseTransparentDataEncryption', pipeline_response) + deserialized = self._deserialize("LogicalDatabaseTransparentDataEncryption", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption/{tdeName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption/{tdeName}"} # type: ignore - @distributed_trace + @overload def create_or_update( self, resource_group_name: str, @@ -259,43 +240,118 @@ def create_or_update( database_name: str, tde_name: Union[str, "_models.TransparentDataEncryptionName"], parameters: _models.LogicalDatabaseTransparentDataEncryption, + *, + content_type: str = "application/json", **kwargs: Any ) -> Optional[_models.LogicalDatabaseTransparentDataEncryption]: """Updates a logical database's transparent data encryption configuration. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the logical database for which the security alert policy is - defined. + defined. Required. :type database_name: str - :param tde_name: The name of the transparent data encryption configuration. + :param tde_name: The name of the transparent data encryption configuration. "current" Required. :type tde_name: str or ~azure.mgmt.sql.models.TransparentDataEncryptionName - :param parameters: The database transparent data encryption. + :param parameters: The database transparent data encryption. Required. :type parameters: ~azure.mgmt.sql.models.LogicalDatabaseTransparentDataEncryption - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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: LogicalDatabaseTransparentDataEncryption or None or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.LogicalDatabaseTransparentDataEncryption or None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + tde_name: Union[str, "_models.TransparentDataEncryptionName"], + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> Optional[_models.LogicalDatabaseTransparentDataEncryption]: + """Updates a logical database's transparent data encryption configuration. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the logical database for which the security alert policy is + defined. Required. + :type database_name: str + :param tde_name: The name of the transparent data encryption configuration. "current" Required. + :type tde_name: str or ~azure.mgmt.sql.models.TransparentDataEncryptionName + :param parameters: The database transparent data encryption. Required. + :type parameters: IO + :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: LogicalDatabaseTransparentDataEncryption or None or the result of cls(response) + :rtype: ~azure.mgmt.sql.models.LogicalDatabaseTransparentDataEncryption or None + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + tde_name: Union[str, "_models.TransparentDataEncryptionName"], + parameters: Union[_models.LogicalDatabaseTransparentDataEncryption, IO], + **kwargs: Any + ) -> Optional[_models.LogicalDatabaseTransparentDataEncryption]: + """Updates a logical database's transparent data encryption configuration. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the logical database for which the security alert policy is + defined. Required. + :type database_name: str + :param tde_name: The name of the transparent data encryption configuration. "current" Required. + :type tde_name: str or ~azure.mgmt.sql.models.TransparentDataEncryptionName + :param parameters: The database transparent data encryption. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.LogicalDatabaseTransparentDataEncryption 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 - :return: LogicalDatabaseTransparentDataEncryption, or the result of cls(response) + :return: LogicalDatabaseTransparentDataEncryption or None or the result of cls(response) :rtype: ~azure.mgmt.sql.models.LogicalDatabaseTransparentDataEncryption or None - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.LogicalDatabaseTransparentDataEncryption]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.LogicalDatabaseTransparentDataEncryption]] - _json = self._serialize.body(parameters, 'LogicalDatabaseTransparentDataEncryption') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "LogicalDatabaseTransparentDataEncryption") request = build_create_or_update_request( resource_group_name=resource_group_name, @@ -306,7 +362,8 @@ def create_or_update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.create_or_update.metadata['url'], + content=_content, + template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) @@ -314,10 +371,9 @@ def create_or_update( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -326,67 +382,58 @@ def create_or_update( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('LogicalDatabaseTransparentDataEncryption', pipeline_response) + deserialized = self._deserialize("LogicalDatabaseTransparentDataEncryption", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('LogicalDatabaseTransparentDataEncryption', pipeline_response) + deserialized = self._deserialize("LogicalDatabaseTransparentDataEncryption", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption/{tdeName}"} # type: ignore - + create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption/{tdeName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.LogicalDatabaseTransparentDataEncryptionListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.LogicalDatabaseTransparentDataEncryption"]: """Gets a list of the logical database's transparent data encryption. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str :param database_name: The name of the logical database for which the transparent data - encryption is defined. + encryption is defined. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either LogicalDatabaseTransparentDataEncryptionListResult - or the result of cls(response) + :return: An iterator like instance of either LogicalDatabaseTransparentDataEncryption or the + result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LogicalDatabaseTransparentDataEncryptionListResult] - :raises: ~azure.core.exceptions.HttpResponseError + ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.LogicalDatabaseTransparentDataEncryption] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.LogicalDatabaseTransparentDataEncryptionListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.LogicalDatabaseTransparentDataEncryptionListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -394,17 +441,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -420,10 +457,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -433,8 +468,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_usages_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_usages_operations.py index 6ed8126a5a8d5..d6e0f8cdc9385 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_usages_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_usages_operations.py @@ -8,9 +8,13 @@ # -------------------------------------------------------------------------- from typing import Any, Callable, Dict, Iterable, Optional, TypeVar -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -20,13 +24,16 @@ from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_list_by_instance_pool_request( resource_group_name: str, instance_pool_name: str, @@ -38,34 +45,32 @@ def build_list_by_instance_pool_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', "2021-02-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2021-02-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}/usages") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}/usages", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "instancePoolName": _SERIALIZER.url("instance_pool_name", instance_pool_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "instancePoolName": _SERIALIZER.url("instance_pool_name", instance_pool_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters if expand_children is not None: - _params['expandChildren'] = _SERIALIZER.query("expand_children", expand_children, 'bool') - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["expandChildren"] = _SERIALIZER.query("expand_children", expand_children, "bool") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class UsagesOperations: """ @@ -86,53 +91,44 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def list_by_instance_pool( - self, - resource_group_name: str, - instance_pool_name: str, - expand_children: Optional[bool] = None, - **kwargs: Any - ) -> Iterable[_models.UsageListResult]: + self, resource_group_name: str, instance_pool_name: str, expand_children: Optional[bool] = None, **kwargs: Any + ) -> Iterable["_models.Usage"]: """Gets all instance pool usage metrics. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param instance_pool_name: The name of the instance pool to be retrieved. + :param instance_pool_name: The name of the instance pool to be retrieved. Required. :type instance_pool_name: str :param expand_children: Optional request parameter to include managed instance usages within the instance pool. Default value is None. :type expand_children: bool - :keyword api_version: Api Version. Default value is "2021-02-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either UsageListResult or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.UsageListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either Usage or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.Usage] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2021-02-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.UsageListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.UsageListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_instance_pool_request( resource_group_name=resource_group_name, instance_pool_name=instance_pool_name, subscription_id=self._config.subscription_id, - api_version=api_version, expand_children=expand_children, - template_url=self.list_by_instance_pool.metadata['url'], + api_version=api_version, + template_url=self.list_by_instance_pool.metadata["url"], headers=_headers, params=_params, ) @@ -140,17 +136,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_instance_pool_request( - resource_group_name=resource_group_name, - instance_pool_name=instance_pool_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - expand_children=expand_children, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -166,10 +152,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -179,8 +163,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_instance_pool.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}/usages"} # type: ignore + list_by_instance_pool.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}/usages"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_virtual_clusters_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_virtual_clusters_operations.py index 846a01a123924..8d0ad7e866b7d 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_virtual_clusters_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_virtual_clusters_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,228 +26,188 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_update_dns_servers_request( - resource_group_name: str, - virtual_cluster_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, virtual_cluster_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}/updateManagedInstanceDnsServers") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}/updateManagedInstanceDnsServers", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "virtualClusterName": _SERIALIZER.url("virtual_cluster_name", virtual_cluster_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "virtualClusterName": _SERIALIZER.url("virtual_cluster_name", virtual_cluster_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="POST", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) -def build_list_request( - subscription_id: str, - **kwargs: Any -) -> HttpRequest: +def build_list_request(subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/virtualClusters") path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_list_by_resource_group_request( - resource_group_name: str, - subscription_id: str, - **kwargs: Any -) -> HttpRequest: +def build_list_by_resource_group_request(resource_group_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) def build_get_request( - resource_group_name: str, - virtual_cluster_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, virtual_cluster_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "virtualClusterName": _SERIALIZER.url("virtual_cluster_name", virtual_cluster_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "virtualClusterName": _SERIALIZER.url("virtual_cluster_name", virtual_cluster_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_delete_request_initial( - resource_group_name: str, - virtual_cluster_name: str, - subscription_id: str, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_delete_request( + resource_group_name: str, virtual_cluster_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "virtualClusterName": _SERIALIZER.url("virtual_cluster_name", virtual_cluster_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "virtualClusterName": _SERIALIZER.url("virtual_cluster_name", virtual_cluster_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') - - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) - - -def build_update_request_initial( - resource_group_name: str, - virtual_cluster_name: str, - subscription_id: str, - *, - json: Optional[_models.VirtualClusterUpdate] = None, - content: Any = None, - **kwargs: Any + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) + + +def build_update_request( + resource_group_name: str, virtual_cluster_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "virtualClusterName": _SERIALIZER.url("virtual_cluster_name", virtual_cluster_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "virtualClusterName": _SERIALIZER.url("virtual_cluster_name", virtual_cluster_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PATCH", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) + class VirtualClustersOperations: """ @@ -264,48 +228,38 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def update_dns_servers( - self, - resource_group_name: str, - virtual_cluster_name: str, - **kwargs: Any + self, resource_group_name: str, virtual_cluster_name: str, **kwargs: Any ) -> _models.UpdateManagedInstanceDnsServersOperation: """Synchronizes the DNS server settings used by the managed instances inside the given virtual cluster. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param virtual_cluster_name: The name of the virtual cluster. + :param virtual_cluster_name: The name of the virtual cluster. Required. :type virtual_cluster_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: UpdateManagedInstanceDnsServersOperation, or the result of cls(response) + :return: UpdateManagedInstanceDnsServersOperation or the result of cls(response) :rtype: ~azure.mgmt.sql.models.UpdateManagedInstanceDnsServersOperation - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.UpdateManagedInstanceDnsServersOperation] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.UpdateManagedInstanceDnsServersOperation] - request = build_update_dns_servers_request( resource_group_name=resource_group_name, virtual_cluster_name=virtual_cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.update_dns_servers.metadata['url'], + template_url=self.update_dns_servers.metadata["url"], headers=_headers, params=_params, ) @@ -313,59 +267,49 @@ def update_dns_servers( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('UpdateManagedInstanceDnsServersOperation', pipeline_response) + deserialized = self._deserialize("UpdateManagedInstanceDnsServersOperation", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - update_dns_servers.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}/updateManagedInstanceDnsServers"} # type: ignore - + update_dns_servers.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}/updateManagedInstanceDnsServers"} # type: ignore @distributed_trace - def list( - self, - **kwargs: Any - ) -> Iterable[_models.VirtualClusterListResult]: + def list(self, **kwargs: Any) -> Iterable["_models.VirtualCluster"]: """Gets a list of all virtualClusters in the subscription. - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VirtualClusterListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.VirtualClusterListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either VirtualCluster or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.VirtualCluster] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VirtualClusterListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualClusterListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_request( subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list.metadata['url'], + template_url=self.list.metadata["url"], headers=_headers, params=_params, ) @@ -373,14 +317,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_request( - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -396,10 +333,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -409,50 +344,39 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/virtualClusters"} # type: ignore + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Sql/virtualClusters"} # type: ignore @distributed_trace - def list_by_resource_group( - self, - resource_group_name: str, - **kwargs: Any - ) -> Iterable[_models.VirtualClusterListResult]: + def list_by_resource_group(self, resource_group_name: str, **kwargs: Any) -> Iterable["_models.VirtualCluster"]: """Gets a list of virtual clusters in a resource group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VirtualClusterListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.VirtualClusterListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either VirtualCluster or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.VirtualCluster] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VirtualClusterListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualClusterListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_resource_group_request( resource_group_name=resource_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_resource_group.metadata['url'], + template_url=self.list_by_resource_group.metadata["url"], headers=_headers, params=_params, ) @@ -460,15 +384,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -484,10 +400,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -497,52 +411,39 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters"} # type: ignore + list_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters"} # type: ignore @distributed_trace - def get( - self, - resource_group_name: str, - virtual_cluster_name: str, - **kwargs: Any - ) -> _models.VirtualCluster: + def get(self, resource_group_name: str, virtual_cluster_name: str, **kwargs: Any) -> _models.VirtualCluster: """Gets a virtual cluster. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param virtual_cluster_name: The name of the virtual cluster. + :param virtual_cluster_name: The name of the virtual cluster. Required. :type virtual_cluster_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VirtualCluster, or the result of cls(response) + :return: VirtualCluster or the result of cls(response) :rtype: ~azure.mgmt.sql.models.VirtualCluster - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VirtualCluster] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualCluster] - request = build_get_request( resource_group_name=resource_group_name, virtual_cluster_name=virtual_cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -550,50 +451,42 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('VirtualCluster', pipeline_response) + deserialized = self._deserialize("VirtualCluster", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - virtual_cluster_name: str, - **kwargs: Any + self, resource_group_name: str, virtual_cluster_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, virtual_cluster_name=virtual_cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -601,10 +494,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -614,26 +506,17 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - virtual_cluster_name: str, - **kwargs: Any - ) -> LROPoller[None]: + def begin_delete(self, resource_group_name: str, virtual_cluster_name: str, **kwargs: Any) -> LROPoller[None]: """Deletes a virtual cluster. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param virtual_cluster_name: The name of the virtual cluster. + :param virtual_cluster_name: The name of the virtual cluster. Required. :type virtual_cluster_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -644,85 +527,83 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, virtual_cluster_name=virtual_cluster_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/virtualClusters/{virtualClusterName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore def _update_initial( self, resource_group_name: str, virtual_cluster_name: str, - parameters: _models.VirtualClusterUpdate, + parameters: Union[_models.VirtualClusterUpdate, IO], **kwargs: Any ) -> Optional[_models.VirtualCluster]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.VirtualCluster]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.VirtualCluster]] - _json = self._serialize.body(parameters, 'VirtualClusterUpdate') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "VirtualClusterUpdate") - request = build_update_request_initial( + request = build_update_request( resource_group_name=resource_group_name, virtual_cluster_name=virtual_cluster_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._update_initial.metadata['url'], + content=_content, + template_url=self._update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -730,10 +611,9 @@ def _update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202]: @@ -742,36 +622,73 @@ def _update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('VirtualCluster', pipeline_response) + deserialized = self._deserialize("VirtualCluster", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore + _update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore - - @distributed_trace + @overload def begin_update( self, resource_group_name: str, virtual_cluster_name: str, parameters: _models.VirtualClusterUpdate, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.VirtualCluster]: """Updates a virtual cluster. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param virtual_cluster_name: The name of the virtual cluster. + :param virtual_cluster_name: The name of the virtual cluster. Required. :type virtual_cluster_name: str - :param parameters: The requested virtual cluster resource state. + :param parameters: The requested virtual cluster resource state. Required. :type parameters: ~azure.mgmt.sql.models.VirtualClusterUpdate - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 VirtualCluster or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.VirtualCluster] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_update( + self, + resource_group_name: str, + virtual_cluster_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.VirtualCluster]: + """Updates a virtual cluster. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param virtual_cluster_name: The name of the virtual cluster. Required. + :type virtual_cluster_name: str + :param parameters: The requested virtual cluster resource state. Required. + :type parameters: IO + :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 @@ -783,20 +700,52 @@ def begin_update( :return: An instance of LROPoller that returns either VirtualCluster or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.VirtualCluster] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_update( + self, + resource_group_name: str, + virtual_cluster_name: str, + parameters: Union[_models.VirtualClusterUpdate, IO], + **kwargs: Any + ) -> LROPoller[_models.VirtualCluster]: + """Updates a virtual cluster. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param virtual_cluster_name: The name of the virtual cluster. Required. + :type virtual_cluster_name: str + :param parameters: The requested virtual cluster resource state. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.VirtualClusterUpdate 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. + :return: An instance of LROPoller that returns either VirtualCluster or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.VirtualCluster] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.VirtualCluster] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualCluster] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._update_initial( # type: ignore resource_group_name=resource_group_name, @@ -804,36 +753,32 @@ def begin_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('VirtualCluster', pipeline_response) + deserialized = self._deserialize("VirtualCluster", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + deserialization_callback=get_long_running_output, ) return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - begin_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore + begin_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/virtualClusters/{virtualClusterName}"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_virtual_network_rules_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_virtual_network_rules_operations.py index ef3e082665d31..2a205fc7e9b6d 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_virtual_network_rules_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_virtual_network_rules_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,166 +26,139 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( - resource_group_name: str, - server_name: str, - virtual_network_rule_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, virtual_network_rule_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "virtualNetworkRuleName": _SERIALIZER.url("virtual_network_rule_name", virtual_network_rule_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "virtualNetworkRuleName": _SERIALIZER.url("virtual_network_rule_name", virtual_network_rule_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) - - -def build_create_or_update_request_initial( - resource_group_name: str, - server_name: str, - virtual_network_rule_name: str, - subscription_id: str, - *, - json: Optional[_models.VirtualNetworkRule] = None, - content: Any = None, - **kwargs: Any + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, server_name: str, virtual_network_rule_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "virtualNetworkRuleName": _SERIALIZER.url("virtual_network_rule_name", virtual_network_rule_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "virtualNetworkRuleName": _SERIALIZER.url("virtual_network_rule_name", virtual_network_rule_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') - - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) - - -def build_delete_request_initial( - resource_group_name: str, - server_name: str, - virtual_network_rule_name: str, - subscription_id: str, - **kwargs: Any + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_delete_request( + resource_group_name: str, server_name: str, virtual_network_rule_name: str, subscription_id: str, **kwargs: Any ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "virtualNetworkRuleName": _SERIALIZER.url("virtual_network_rule_name", virtual_network_rule_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "virtualNetworkRuleName": _SERIALIZER.url("virtual_network_rule_name", virtual_network_rule_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_server_request( - resource_group_name: str, - server_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class VirtualNetworkRulesOperations: """ @@ -202,51 +179,40 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - virtual_network_rule_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, virtual_network_rule_name: str, **kwargs: Any ) -> _models.VirtualNetworkRule: """Gets a virtual network rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param virtual_network_rule_name: The name of the virtual network rule. + :param virtual_network_rule_name: The name of the virtual network rule. Required. :type virtual_network_rule_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VirtualNetworkRule, or the result of cls(response) + :return: VirtualNetworkRule or the result of cls(response) :rtype: ~azure.mgmt.sql.models.VirtualNetworkRule - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VirtualNetworkRule] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualNetworkRule] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, virtual_network_rule_name=virtual_network_rule_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -254,49 +220,51 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('VirtualNetworkRule', pipeline_response) + deserialized = self._deserialize("VirtualNetworkRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore def _create_or_update_initial( self, resource_group_name: str, server_name: str, virtual_network_rule_name: str, - parameters: _models.VirtualNetworkRule, + parameters: Union[_models.VirtualNetworkRule, IO], **kwargs: Any ) -> Optional[_models.VirtualNetworkRule]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.VirtualNetworkRule]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.VirtualNetworkRule]] - _json = self._serialize.body(parameters, 'VirtualNetworkRule') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "VirtualNetworkRule") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, virtual_network_rule_name=virtual_network_rule_name, @@ -304,7 +272,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -312,10 +281,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -324,42 +292,120 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('VirtualNetworkRule', pipeline_response) + deserialized = self._deserialize("VirtualNetworkRule", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('VirtualNetworkRule', pipeline_response) + deserialized = self._deserialize("VirtualNetworkRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, server_name: str, virtual_network_rule_name: str, parameters: _models.VirtualNetworkRule, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.VirtualNetworkRule]: """Creates or updates an existing virtual network rule. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param virtual_network_rule_name: The name of the virtual network rule. + :param virtual_network_rule_name: The name of the virtual network rule. Required. :type virtual_network_rule_name: str - :param parameters: The requested virtual Network Rule Resource state. + :param parameters: The requested virtual Network Rule Resource state. Required. :type parameters: ~azure.mgmt.sql.models.VirtualNetworkRule - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 VirtualNetworkRule or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.VirtualNetworkRule] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + virtual_network_rule_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.VirtualNetworkRule]: + """Creates or updates an existing virtual network rule. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param virtual_network_rule_name: The name of the virtual network rule. Required. + :type virtual_network_rule_name: str + :param parameters: The requested virtual Network Rule Resource state. Required. + :type parameters: IO + :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 VirtualNetworkRule or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.VirtualNetworkRule] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + virtual_network_rule_name: str, + parameters: Union[_models.VirtualNetworkRule, IO], + **kwargs: Any + ) -> LROPoller[_models.VirtualNetworkRule]: + """Creates or updates an existing virtual network rule. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param virtual_network_rule_name: The name of the virtual network rule. Required. + :type virtual_network_rule_name: str + :param parameters: The requested virtual Network Rule Resource state. Is either a model type or + a IO type. Required. + :type parameters: ~azure.mgmt.sql.models.VirtualNetworkRule 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 @@ -371,20 +417,17 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either VirtualNetworkRule or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.VirtualNetworkRule] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.VirtualNetworkRule] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualNetworkRule] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -393,66 +436,55 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('VirtualNetworkRule', pipeline_response) + deserialized = self._deserialize("VirtualNetworkRule", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - virtual_network_rule_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, virtual_network_rule_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, virtual_network_rule_name=virtual_network_rule_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -460,10 +492,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -473,29 +504,21 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - virtual_network_rule_name: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, server_name: str, virtual_network_rule_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes the virtual network rule with the given name. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param virtual_network_rule_name: The name of the virtual network rule. + :param virtual_network_rule_name: The name of the virtual network rule. Required. :type virtual_network_rule_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -506,99 +529,84 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, server_name=server_name, virtual_network_rule_name=virtual_network_rule_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName}"} # type: ignore @distributed_trace def list_by_server( - self, - resource_group_name: str, - server_name: str, - **kwargs: Any - ) -> Iterable[_models.VirtualNetworkRuleListResult]: + self, resource_group_name: str, server_name: str, **kwargs: Any + ) -> Iterable["_models.VirtualNetworkRule"]: """Gets a list of virtual network rules in a server. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VirtualNetworkRuleListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.VirtualNetworkRuleListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either VirtualNetworkRule or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.VirtualNetworkRule] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.VirtualNetworkRuleListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualNetworkRuleListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_server_request( resource_group_name=resource_group_name, server_name=server_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_server.metadata['url'], + template_url=self.list_by_server.metadata["url"], headers=_headers, params=_params, ) @@ -606,16 +614,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_server_request( - resource_group_name=resource_group_name, - server_name=server_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -631,10 +630,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -644,8 +641,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_server.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules"} # type: ignore + list_by_server.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/virtualNetworkRules"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_workload_classifiers_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_workload_classifiers_operations.py index 9448e0c8cdf21..79f652c01f918 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_workload_classifiers_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_workload_classifiers_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -41,89 +48,78 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "workloadGroupName": _SERIALIZER.url("workload_group_name", workload_group_name, 'str'), - "workloadClassifierName": _SERIALIZER.url("workload_classifier_name", workload_classifier_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "workloadGroupName": _SERIALIZER.url("workload_group_name", workload_group_name, "str"), + "workloadClassifierName": _SERIALIZER.url("workload_classifier_name", workload_classifier_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, server_name: str, database_name: str, workload_group_name: str, workload_classifier_name: str, subscription_id: str, - *, - json: Optional[_models.WorkloadClassifier] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "workloadGroupName": _SERIALIZER.url("workload_group_name", workload_group_name, 'str'), - "workloadClassifierName": _SERIALIZER.url("workload_classifier_name", workload_classifier_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "workloadGroupName": _SERIALIZER.url("workload_group_name", workload_group_name, "str"), + "workloadClassifierName": _SERIALIZER.url("workload_classifier_name", workload_classifier_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_request_initial( +def build_delete_request( resource_group_name: str, server_name: str, database_name: str, @@ -134,29 +130,27 @@ def build_delete_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "workloadGroupName": _SERIALIZER.url("workload_group_name", workload_group_name, 'str'), - "workloadClassifierName": _SERIALIZER.url("workload_classifier_name", workload_classifier_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "workloadGroupName": _SERIALIZER.url("workload_group_name", workload_group_name, "str"), + "workloadClassifierName": _SERIALIZER.url("workload_classifier_name", workload_classifier_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_workload_group_request( @@ -170,34 +164,32 @@ def build_list_by_workload_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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "workloadGroupName": _SERIALIZER.url("workload_group_name", workload_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "workloadGroupName": _SERIALIZER.url("workload_group_name", workload_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class WorkloadClassifiersOperations: """ @@ -218,7 +210,6 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( self, @@ -232,37 +223,31 @@ def get( """Gets a workload classifier. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param workload_group_name: The name of the workload group from which to receive the classifier - from. + from. Required. :type workload_group_name: str - :param workload_classifier_name: The name of the workload classifier. + :param workload_classifier_name: The name of the workload classifier. Required. :type workload_classifier_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: WorkloadClassifier, or the result of cls(response) + :return: WorkloadClassifier or the result of cls(response) :rtype: ~azure.mgmt.sql.models.WorkloadClassifier - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.WorkloadClassifier] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.WorkloadClassifier] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -271,7 +256,7 @@ def get( workload_classifier_name=workload_classifier_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -279,25 +264,23 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('WorkloadClassifier', pipeline_response) + deserialized = self._deserialize("WorkloadClassifier", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore def _create_or_update_initial( self, @@ -306,24 +289,28 @@ def _create_or_update_initial( database_name: str, workload_group_name: str, workload_classifier_name: str, - parameters: _models.WorkloadClassifier, + parameters: Union[_models.WorkloadClassifier, IO], **kwargs: Any ) -> Optional[_models.WorkloadClassifier]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.WorkloadClassifier]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.WorkloadClassifier]] - _json = self._serialize.body(parameters, 'WorkloadClassifier') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "WorkloadClassifier") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -333,7 +320,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -341,10 +329,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -353,20 +340,19 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('WorkloadClassifier', pipeline_response) + deserialized = self._deserialize("WorkloadClassifier", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('WorkloadClassifier', pipeline_response) + deserialized = self._deserialize("WorkloadClassifier", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore - + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, @@ -375,27 +361,77 @@ def begin_create_or_update( workload_group_name: str, workload_classifier_name: str, parameters: _models.WorkloadClassifier, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.WorkloadClassifier]: """Creates or updates a workload classifier. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param workload_group_name: The name of the workload group from which to receive the classifier - from. + from. Required. :type workload_group_name: str :param workload_classifier_name: The name of the workload classifier to create/update. + Required. :type workload_classifier_name: str - :param parameters: The properties of the workload classifier. + :param parameters: The properties of the workload classifier. Required. :type parameters: ~azure.mgmt.sql.models.WorkloadClassifier - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 WorkloadClassifier or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.WorkloadClassifier] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + workload_group_name: str, + workload_classifier_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.WorkloadClassifier]: + """Creates or updates a workload classifier. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param workload_group_name: The name of the workload group from which to receive the classifier + from. Required. + :type workload_group_name: str + :param workload_classifier_name: The name of the workload classifier to create/update. + Required. + :type workload_classifier_name: str + :param parameters: The properties of the workload classifier. Required. + :type parameters: IO + :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 @@ -407,20 +443,63 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either WorkloadClassifier or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.WorkloadClassifier] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + workload_group_name: str, + workload_classifier_name: str, + parameters: Union[_models.WorkloadClassifier, IO], + **kwargs: Any + ) -> LROPoller[_models.WorkloadClassifier]: + """Creates or updates a workload classifier. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param workload_group_name: The name of the workload group from which to receive the classifier + from. Required. + :type workload_group_name: str + :param workload_classifier_name: The name of the workload classifier to create/update. + Required. + :type workload_classifier_name: str + :param parameters: The properties of the workload classifier. Is either a model type or a IO + type. Required. + :type parameters: ~azure.mgmt.sql.models.WorkloadClassifier 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. + :return: An instance of LROPoller that returns either WorkloadClassifier or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.WorkloadClassifier] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.WorkloadClassifier] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.WorkloadClassifier] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -431,39 +510,35 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('WorkloadClassifier', pipeline_response) + deserialized = self._deserialize("WorkloadClassifier", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements self, @@ -474,19 +549,16 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements workload_classifier_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -494,7 +566,7 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements workload_classifier_name=workload_classifier_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -502,10 +574,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -515,11 +586,10 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements + def begin_delete( self, resource_group_name: str, server_name: str, @@ -531,20 +601,17 @@ def begin_delete( # pylint: disable=inconsistent-return-statements """Deletes a workload classifier. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param workload_group_name: The name of the workload group from which to receive the classifier - from. + from. Required. :type workload_group_name: str - :param workload_classifier_name: The name of the workload classifier to delete. + :param workload_classifier_name: The name of the workload classifier to delete. Required. :type workload_classifier_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -555,19 +622,16 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, @@ -576,81 +640,67 @@ def begin_delete( # pylint: disable=inconsistent-return-statements workload_group_name=workload_group_name, workload_classifier_name=workload_classifier_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}"} # type: ignore @distributed_trace def list_by_workload_group( - self, - resource_group_name: str, - server_name: str, - database_name: str, - workload_group_name: str, - **kwargs: Any - ) -> Iterable[_models.WorkloadClassifierListResult]: + self, resource_group_name: str, server_name: str, database_name: str, workload_group_name: str, **kwargs: Any + ) -> Iterable["_models.WorkloadClassifier"]: """Gets the list of workload classifiers for a workload group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str :param workload_group_name: The name of the workload group from which to receive the - classifiers from. + classifiers from. Required. :type workload_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either WorkloadClassifierListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.WorkloadClassifierListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either WorkloadClassifier or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.WorkloadClassifier] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.WorkloadClassifierListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.WorkloadClassifierListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_workload_group_request( resource_group_name=resource_group_name, server_name=server_name, @@ -658,7 +708,7 @@ def prepare_request(next_link=None): workload_group_name=workload_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_workload_group.metadata['url'], + template_url=self.list_by_workload_group.metadata["url"], headers=_headers, params=_params, ) @@ -666,18 +716,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_workload_group_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - workload_group_name=workload_group_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -693,10 +732,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -706,8 +743,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_workload_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers"} # type: ignore + list_by_workload_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers"} # type: ignore diff --git a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_workload_groups_operations.py b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_workload_groups_operations.py index 9084c4c09cd79..da62fffa34c0f 100644 --- a/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_workload_groups_operations.py +++ b/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/operations/_workload_groups_operations.py @@ -6,11 +6,15 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union, cast - -from msrest import Serializer - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpResponse @@ -22,13 +26,16 @@ from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models as _models +from .._serialization import Serializer from .._vendor import _convert_request, _format_url_section -T = TypeVar('T') + +T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False + def build_get_request( resource_group_name: str, server_name: str, @@ -40,86 +47,75 @@ 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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "workloadGroupName": _SERIALIZER.url("workload_group_name", workload_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "workloadGroupName": _SERIALIZER.url("workload_group_name", workload_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_create_or_update_request_initial( +def build_create_or_update_request( resource_group_name: str, server_name: str, database_name: str, workload_group_name: str, subscription_id: str, - *, - json: Optional[_models.WorkloadGroup] = None, - content: Any = None, **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', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', None)) # type: Optional[str] - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "workloadGroupName": _SERIALIZER.url("workload_group_name", workload_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "workloadGroupName": _SERIALIZER.url("workload_group_name", workload_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if content_type is not None: - _headers['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest( - method="PUT", - url=_url, - params=_params, - headers=_headers, - json=json, - content=content, - **kwargs - ) + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_delete_request_initial( +def build_delete_request( resource_group_name: str, server_name: str, database_name: str, @@ -129,67 +125,59 @@ def build_delete_request_initial( ) -> HttpRequest: _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "workloadGroupName": _SERIALIZER.url("workload_group_name", workload_group_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "workloadGroupName": _SERIALIZER.url("workload_group_name", workload_group_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - return HttpRequest( - method="DELETE", - url=_url, - params=_params, - **kwargs - ) + return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) def build_list_by_database_request( - resource_group_name: str, - server_name: str, - database_name: str, - subscription_id: str, - **kwargs: Any + resource_group_name: str, server_name: str, database_name: str, subscription_id: str, **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', "2020-11-01-preview")) # type: str - accept = _headers.pop('Accept', "application/json") + api_version = kwargs.pop("api_version", _params.pop("api-version", "2020-11-01-preview")) # type: str + accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups") # pylint: disable=line-too-long + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups", + ) # pylint: disable=line-too-long path_format_arguments = { - "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), - "serverName": _SERIALIZER.url("server_name", server_name, 'str'), - "databaseName": _SERIALIZER.url("database_name", database_name, 'str'), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), + "serverName": _SERIALIZER.url("server_name", server_name, "str"), + "databaseName": _SERIALIZER.url("database_name", database_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url = _format_url_section(_url, **path_format_arguments) # Construct parameters - _params['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - _headers['Accept'] = _SERIALIZER.header("accept", accept, 'str') + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - return HttpRequest( - method="GET", - url=_url, - params=_params, - headers=_headers, - **kwargs - ) class WorkloadGroupsOperations: """ @@ -210,47 +198,35 @@ def __init__(self, *args, **kwargs): self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - @distributed_trace def get( - self, - resource_group_name: str, - server_name: str, - database_name: str, - workload_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, workload_group_name: str, **kwargs: Any ) -> _models.WorkloadGroup: """Gets a workload group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param workload_group_name: The name of the workload group. + :param workload_group_name: The name of the workload group. Required. :type workload_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: WorkloadGroup, or the result of cls(response) + :return: WorkloadGroup or the result of cls(response) :rtype: ~azure.mgmt.sql.models.WorkloadGroup - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.WorkloadGroup] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.WorkloadGroup] - request = build_get_request( resource_group_name=resource_group_name, server_name=server_name, @@ -258,7 +234,7 @@ def get( workload_group_name=workload_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata['url'], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -266,25 +242,23 @@ def get( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize('WorkloadGroup', pipeline_response) + deserialized = self._deserialize("WorkloadGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore - + get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore def _create_or_update_initial( self, @@ -292,24 +266,28 @@ def _create_or_update_initial( server_name: str, database_name: str, workload_group_name: str, - parameters: _models.WorkloadGroup, + parameters: Union[_models.WorkloadGroup, IO], **kwargs: Any ) -> Optional[_models.WorkloadGroup]: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[_models.WorkloadGroup]] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[Optional[_models.WorkloadGroup]] - _json = self._serialize.body(parameters, 'WorkloadGroup') + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IO, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "WorkloadGroup") - request = build_create_or_update_request_initial( + request = build_create_or_update_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, @@ -318,7 +296,8 @@ def _create_or_update_initial( api_version=api_version, content_type=content_type, json=_json, - template_url=self._create_or_update_initial.metadata['url'], + content=_content, + template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) @@ -326,10 +305,9 @@ def _create_or_update_initial( request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 201, 202]: @@ -338,20 +316,19 @@ def _create_or_update_initial( deserialized = None if response.status_code == 200: - deserialized = self._deserialize('WorkloadGroup', pipeline_response) + deserialized = self._deserialize("WorkloadGroup", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize('WorkloadGroup', pipeline_response) + deserialized = self._deserialize("WorkloadGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore + _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore - - @distributed_trace + @overload def begin_create_or_update( self, resource_group_name: str, @@ -359,24 +336,109 @@ def begin_create_or_update( database_name: str, workload_group_name: str, parameters: _models.WorkloadGroup, + *, + content_type: str = "application/json", **kwargs: Any ) -> LROPoller[_models.WorkloadGroup]: """Creates or updates a workload group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param workload_group_name: The name of the workload group. + :param workload_group_name: The name of the workload group. Required. :type workload_group_name: str - :param parameters: The requested workload group state. + :param parameters: The requested workload group state. Required. :type parameters: ~azure.mgmt.sql.models.WorkloadGroup - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str + :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 WorkloadGroup or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.WorkloadGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + workload_group_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.WorkloadGroup]: + """Creates or updates a workload group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param workload_group_name: The name of the workload group. Required. + :type workload_group_name: str + :param parameters: The requested workload group state. Required. + :type parameters: IO + :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 WorkloadGroup or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.WorkloadGroup] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + server_name: str, + database_name: str, + workload_group_name: str, + parameters: Union[_models.WorkloadGroup, IO], + **kwargs: Any + ) -> LROPoller[_models.WorkloadGroup]: + """Creates or updates a workload group. + + :param resource_group_name: The name of the resource group that contains the resource. You can + obtain this value from the Azure Resource Manager API or the portal. Required. + :type resource_group_name: str + :param server_name: The name of the server. Required. + :type server_name: str + :param database_name: The name of the database. Required. + :type database_name: str + :param workload_group_name: The name of the workload group. Required. + :type workload_group_name: str + :param parameters: The requested workload group state. Is either a model type or a IO type. + Required. + :type parameters: ~azure.mgmt.sql.models.WorkloadGroup 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 @@ -388,20 +450,17 @@ def begin_create_or_update( :return: An instance of LROPoller that returns either WorkloadGroup or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.sql.models.WorkloadGroup] - :raises: ~azure.core.exceptions.HttpResponseError + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - content_type = kwargs.pop('content_type', _headers.pop('Content-Type', "application/json")) # type: Optional[str] - cls = kwargs.pop('cls', None) # type: ClsType[_models.WorkloadGroup] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + cls = kwargs.pop("cls", None) # type: ClsType[_models.WorkloadGroup] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._create_or_update_initial( # type: ignore resource_group_name=resource_group_name, @@ -411,68 +470,56 @@ def begin_create_or_update( parameters=parameters, api_version=api_version, content_type=content_type, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize('WorkloadGroup', pipeline_response) + deserialized = self._deserialize("WorkloadGroup", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore + begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore def _delete_initial( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - workload_group_name: str, - **kwargs: Any + self, resource_group_name: str, server_name: str, database_name: str, workload_group_name: str, **kwargs: Any ) -> None: - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] - - request = build_delete_request_initial( + request = build_delete_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, workload_group_name=workload_group_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata['url'], + template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) @@ -480,10 +527,9 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements request.url = self._client.format_url(request.url) # type: ignore pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, - stream=False, - **kwargs + request, stream=False, **kwargs ) + response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: @@ -493,32 +539,23 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore - + _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore @distributed_trace - def begin_delete( # pylint: disable=inconsistent-return-statements - self, - resource_group_name: str, - server_name: str, - database_name: str, - workload_group_name: str, - **kwargs: Any + def begin_delete( + self, resource_group_name: str, server_name: str, database_name: str, workload_group_name: str, **kwargs: Any ) -> LROPoller[None]: """Deletes a workload group. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :param workload_group_name: The name of the workload group to delete. + :param workload_group_name: The name of the workload group to delete. Required. :type workload_group_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: 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 @@ -529,19 +566,16 @@ def begin_delete( # pylint: disable=inconsistent-return-statements 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 + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[None] - polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - lro_delay = kwargs.pop( - 'polling_interval', - self._config.polling_interval - ) - cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[None] + polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] if cont_token is None: raw_result = self._delete_initial( # type: ignore resource_group_name=resource_group_name, @@ -549,84 +583,71 @@ def begin_delete( # pylint: disable=inconsistent-return-statements database_name=database_name, workload_group_name=workload_group_name, api_version=api_version, - cls=lambda x,y,z: x, + cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs ) - kwargs.pop('error_map', None) + kwargs.pop("error_map", None) - def get_long_running_output(pipeline_response): + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: return cls(pipeline_response, None, {}) - if polling is True: - polling_method = cast(PollingMethod, ARMPolling( - lro_delay, - - - **kwargs - )) # type: PollingMethod - elif polling is False: polling_method = cast(PollingMethod, NoPolling()) - else: polling_method = polling + polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling if cont_token: return LROPoller.from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, - deserialization_callback=get_long_running_output + 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.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore + begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}"} # type: ignore @distributed_trace def list_by_database( - self, - resource_group_name: str, - server_name: str, - database_name: str, - **kwargs: Any - ) -> Iterable[_models.WorkloadGroupListResult]: + self, resource_group_name: str, server_name: str, database_name: str, **kwargs: Any + ) -> Iterable["_models.WorkloadGroup"]: """Gets the list of workload groups. :param resource_group_name: The name of the resource group that contains the resource. You can - obtain this value from the Azure Resource Manager API or the portal. + obtain this value from the Azure Resource Manager API or the portal. Required. :type resource_group_name: str - :param server_name: The name of the server. + :param server_name: The name of the server. Required. :type server_name: str - :param database_name: The name of the database. + :param database_name: The name of the database. Required. :type database_name: str - :keyword api_version: Api Version. Default value is "2020-11-01-preview". Note that overriding - this default value may result in unsupported behavior. - :paramtype api_version: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either WorkloadGroupListResult or the result of - cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.WorkloadGroupListResult] - :raises: ~azure.core.exceptions.HttpResponseError + :return: An iterator like instance of either WorkloadGroup or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.sql.models.WorkloadGroup] + :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop('api_version', _params.pop('api-version', "2020-11-01-preview")) # type: str - cls = kwargs.pop('cls', None) # type: ClsType[_models.WorkloadGroupListResult] + api_version = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) # type: str + cls = kwargs.pop("cls", None) # type: ClsType[_models.WorkloadGroupListResult] + + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {}) or {}) - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {}) or {}) def prepare_request(next_link=None): if not next_link: - + request = build_list_by_database_request( resource_group_name=resource_group_name, server_name=server_name, database_name=database_name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_by_database.metadata['url'], + template_url=self.list_by_database.metadata["url"], headers=_headers, params=_params, ) @@ -634,17 +655,7 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) # type: ignore else: - - request = build_list_by_database_request( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=next_link, - headers=_headers, - params=_params, - ) + request = HttpRequest("GET", next_link) request = _convert_request(request) request.url = self._client.format_url(request.url) # type: ignore request.method = "GET" @@ -660,10 +671,8 @@ def extract_data(pipeline_response): def get_next(next_link=None): request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access - request, - stream=False, - **kwargs + pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + request, stream=False, **kwargs ) response = pipeline_response.http_response @@ -673,8 +682,6 @@ def get_next(next_link=None): return pipeline_response + return ItemPaged(get_next, extract_data) - return ItemPaged( - get_next, extract_data - ) - list_by_database.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups"} # type: ignore + list_by_database.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups"} # type: ignore